mirror of
https://github.com/wassname/talk.git
synced 2026-08-12 12:30:39 +08:00
feat: skip username validation for SSO users (#2627)
This commit is contained in:
@@ -93,6 +93,7 @@ export const signupHandler = ({
|
||||
// start with.
|
||||
role: GQLUSER_ROLE.COMMENTER,
|
||||
},
|
||||
{},
|
||||
now
|
||||
);
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ export const installHandler = ({
|
||||
profile,
|
||||
role: GQLUSER_ROLE.ADMIN,
|
||||
},
|
||||
{},
|
||||
req.coral.now
|
||||
);
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ export default class FacebookStrategy extends OAuth2Strategy<
|
||||
avatar,
|
||||
profile,
|
||||
},
|
||||
{},
|
||||
now
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ export default class GoogleStrategy extends OAuth2Strategy<
|
||||
avatar,
|
||||
profile,
|
||||
},
|
||||
{},
|
||||
now
|
||||
);
|
||||
}
|
||||
|
||||
@@ -193,6 +193,7 @@ export async function findOrCreateOIDCUser(
|
||||
avatar: picture,
|
||||
profile,
|
||||
},
|
||||
{},
|
||||
now
|
||||
);
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ export async function findOrCreateSSOUser(
|
||||
emailVerified: true,
|
||||
profile,
|
||||
},
|
||||
{ skipUsernameValidation: true },
|
||||
now
|
||||
);
|
||||
} else if (iat && needsSSOUpdate(decodedToken.user, user)) {
|
||||
|
||||
@@ -86,8 +86,11 @@ import {
|
||||
} from "./download/token";
|
||||
import { validateEmail, validatePassword, validateUsername } from "./helpers";
|
||||
|
||||
function validateFindOrCreateUserInput(input: FindOrCreateUser) {
|
||||
if (input.username) {
|
||||
function validateFindOrCreateUserInput(
|
||||
input: FindOrCreateUser,
|
||||
options: FindOrCreateUserOptions
|
||||
) {
|
||||
if (input.username && !options.skipUsernameValidation) {
|
||||
validateUsername(input.username);
|
||||
}
|
||||
|
||||
@@ -108,14 +111,19 @@ function validateFindOrCreateUserInput(input: FindOrCreateUser) {
|
||||
|
||||
export type FindOrCreateUser = FindOrCreateUserInput;
|
||||
|
||||
export interface FindOrCreateUserOptions {
|
||||
skipUsernameValidation?: boolean;
|
||||
}
|
||||
|
||||
export async function findOrCreate(
|
||||
mongo: Db,
|
||||
tenant: Tenant,
|
||||
input: FindOrCreateUser,
|
||||
options: FindOrCreateUserOptions,
|
||||
now: Date
|
||||
) {
|
||||
// Validate the input.
|
||||
validateFindOrCreateUserInput(input);
|
||||
validateFindOrCreateUserInput(input, options);
|
||||
|
||||
const user = await findOrCreateUser(mongo, tenant.id, input, now);
|
||||
|
||||
@@ -125,15 +133,17 @@ export async function findOrCreate(
|
||||
}
|
||||
|
||||
export type CreateUser = FindOrCreateUserInput;
|
||||
export type CreateUserOptions = FindOrCreateUserOptions;
|
||||
|
||||
export async function create(
|
||||
mongo: Db,
|
||||
tenant: Tenant,
|
||||
input: CreateUser,
|
||||
options: CreateUserOptions,
|
||||
now: Date
|
||||
) {
|
||||
// Validate the input.
|
||||
validateFindOrCreateUserInput(input);
|
||||
validateFindOrCreateUserInput(input, options);
|
||||
|
||||
if (input.id) {
|
||||
// Try to check to see if there is a user with the same ID before we try to
|
||||
|
||||
Reference in New Issue
Block a user