fix: move displayName into auth integrations

This commit is contained in:
Wyatt Johnson
2018-07-23 13:14:34 -06:00
parent 13d293b9aa
commit 4b5c7c1c7b
4 changed files with 16 additions and 22 deletions
+4 -15
View File
@@ -23,11 +23,6 @@ const SignupBodySchema = Joi.object().keys({
email: Joi.string().trim(),
});
// Extends the default signup body schema to allow the displayName to be set.
const SignupDisplayNameBodySchema = SignupBodySchema.keys({
displayName: Joi.string().trim(),
});
export interface SignupOptions {
db: Db;
signingConfig: JWTSigningConfig;
@@ -50,15 +45,10 @@ export const signupHandler = (options: SignupOptions): RequestHandler => async (
return next(new Error("integration is disabled"));
}
// Get the fields from the body. We condition on the display name being
// enabled to allow the display name to be stripped in the event that the
// display name is not enabled, yielding a displayName being `undefined`,
// which will not be set in the resultant document. Validate will throw an
// error if the body does not conform to the specification.
const { username, password, email, displayName }: SignupBody = validate(
tenant.auth.displayNameEnable
? SignupDisplayNameBodySchema
: SignupBodySchema,
// Get the fields from the body. Validate will throw an error if the body
// does not conform to the specification.
const { username, password, email }: SignupBody = validate(
SignupBodySchema,
req.body
);
@@ -72,7 +62,6 @@ export const signupHandler = (options: SignupOptions): RequestHandler => async (
const user = await upsert(options.db, tenant, {
email,
username,
displayName,
password,
profiles: [profile],
// New users signing up via local auth will have the commenter role to
@@ -131,7 +131,7 @@ export async function findOrCreateOIDCUser(
name,
nickname,
}: OIDCIDToken = validate(
tenant.auth.displayNameEnable
tenant.auth.integrations.oidc!.displayNameEnable
? OIDCDisplayNameIDTokenSchema
: OIDCIDTokenSchema,
token
@@ -57,7 +57,7 @@ export async function findOrCreateSSOUser(
// Unpack/validate the token content.
const { id, email, username, displayName, avatar }: SSOUserProfile = validate(
tenant.auth.displayNameEnable
tenant.auth.integrations.sso!.displayNameEnable
? SSODisplayNameUserProfileSchema
: SSOUserProfileSchema,
token.user