Skip to content

Commit

Permalink
Merge pull request #332 from Shurtu-gal/fix/password
Browse files Browse the repository at this point in the history
fix(auth-plugin): throw error on password field
  • Loading branch information
overbit authored Jan 30, 2024
2 parents 8240b1a + 533ae5b commit 23317d6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions plugins/auth-auth0/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/auth-auth0/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplication/plugin-auth-auth0",
"version": "1.0.4",
"version": "1.0.5",
"description": "Auth0 plugin for Amplication",
"main": "dist/index.js",
"scripts": {
Expand Down
25 changes: 14 additions & 11 deletions plugins/auth-auth0/src/utils/createAuthProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const NEW_DATE_EXPRESSION = builders.newExpression(DATE_ID, []);
export const NEW_JSON_EXPRESSION = builders.objectExpression([
builders.objectProperty(
builders.stringLiteral("foo"),
builders.stringLiteral("bar")
builders.stringLiteral("bar"),
),
]);

Expand All @@ -32,7 +32,7 @@ export const DEFAULT_ROLE_LITERAL = builders.arrayExpression([

export function createAuthEntityObjectCustomProperties(
authEntity: Entity,
defaultValues: Record<string, unknown>
defaultValues: Record<string, unknown>,
): namedTypes.ObjectProperty[] {
return authEntity.fields
.filter((field) => field.required)
Expand All @@ -45,15 +45,15 @@ export function createAuthEntityObjectCustomProperties(
builders.objectProperty(
builders.identifier(field.name),
// @ts-ignore
value
)
value,
),
);
}

export function createDefaultValue(
field: EntityField,
entity: Entity,
defaultValue: unknown
defaultValue: unknown,
): namedTypes.Expression | null {
switch (field.dataType) {
case EnumDataType.SingleLineText:
Expand Down Expand Up @@ -93,10 +93,10 @@ export function createDefaultValue(
const [firstOption] = options;
return defaultValue
? memberExpression`${createEnumName(field, entity)}.${pascalCase(
defaultValue as string
defaultValue as string,
)}`
: memberExpression`${createEnumName(field, entity)}.${pascalCase(
firstOption.label
firstOption.label,
)}`;
}
case EnumDataType.Boolean: {
Expand All @@ -114,8 +114,7 @@ export function createDefaultValue(
}
case EnumDataType.Id:
case EnumDataType.CreatedAt:
case EnumDataType.UpdatedAt:
case EnumDataType.Password: {
case EnumDataType.UpdatedAt: {
return null;
}
case EnumDataType.Username: {
Expand All @@ -127,14 +126,18 @@ export function createDefaultValue(
return defaultValue
? builders.arrayExpression(
(defaultValue as string[]).map((item) =>
builders.stringLiteral(item)
)
builders.stringLiteral(item),
),
)
: DEFAULT_ROLE_LITERAL;
}
case EnumDataType.Lookup: {
return null;
}
case EnumDataType.Password: {
// Throw error on presence of password field in auth entity
throw new Error("Password field is not supported with Auth0 plugin");
}
default: {
throw new Error(`Unexpected data type: ${field.dataType}`);
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/auth-keycloak/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/auth-keycloak/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplication/plugin-auth-keycloak",
"version": "0.0.1",
"version": "0.0.2",
"description": "Keycloak Authentication plugin for Amplication",
"main": "dist/index.js",
"nx": {},
Expand Down
7 changes: 5 additions & 2 deletions plugins/auth-keycloak/src/utils/createAuthProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ export function createDefaultValue(
}
case EnumDataType.Id:
case EnumDataType.CreatedAt:
case EnumDataType.UpdatedAt:
case EnumDataType.Password: {
case EnumDataType.UpdatedAt: {
return null;
}
case EnumDataType.Username: {
Expand All @@ -136,6 +135,10 @@ export function createDefaultValue(
case EnumDataType.Lookup: {
return null;
}
case EnumDataType.Password: {
// Throw error on presence of password field in auth entity
throw new Error("Password field is not supported with Keycloak plugin");
}
default: {
throw new Error(`Unexpected data type: ${field.dataType}`);
}
Expand Down

0 comments on commit 23317d6

Please sign in to comment.