Fix email not verified issue while login through sso (#13631)
In this PR: - fix race condition while getting token and redirecting to workspace domain (missing await) - add userFriendlyMessage when user does not have password and we try to log in using password - refactor computePartialUserFromUserPayload to remove side effect - add isEmailAlreadyVerified in userPayload that will set user.isEmailVerified to true
This commit is contained in:
@@ -159,6 +159,9 @@ export class AuthService {
|
||||
throw new AuthException(
|
||||
'Incorrect login method',
|
||||
AuthExceptionCode.INVALID_INPUT,
|
||||
{
|
||||
userFriendlyMessage: t`User was not created with email/password`,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -239,7 +242,7 @@ export class AuthService {
|
||||
|
||||
if (params.userData.type === 'newUser') {
|
||||
const partialUserWithPicture =
|
||||
await this.signInUpService.computeParamsForNewUser(
|
||||
await this.signInUpService.computePartialUserFromUserPayload(
|
||||
params.userData.newUserPayload,
|
||||
params.authParams,
|
||||
);
|
||||
@@ -725,6 +728,7 @@ export class AuthService {
|
||||
lastName,
|
||||
email,
|
||||
picture,
|
||||
isEmailAlreadyVerified: true,
|
||||
},
|
||||
{
|
||||
provider: authProvider,
|
||||
@@ -780,6 +784,7 @@ export class AuthService {
|
||||
email,
|
||||
picture,
|
||||
locale,
|
||||
isEmailAlreadyVerified: true,
|
||||
},
|
||||
existingUser,
|
||||
);
|
||||
|
||||
+18
-10
@@ -57,14 +57,11 @@ export class SignInUpService {
|
||||
private readonly userService: UserService,
|
||||
) {}
|
||||
|
||||
async computeParamsForNewUser(
|
||||
newUserParams: SignInUpNewUserPayload,
|
||||
async computePartialUserFromUserPayload(
|
||||
newUserPayload: SignInUpNewUserPayload,
|
||||
authParams: AuthProviderWithPasswordType['authParams'],
|
||||
) {
|
||||
if (!newUserParams.firstName) newUserParams.firstName = '';
|
||||
if (!newUserParams.lastName) newUserParams.lastName = '';
|
||||
|
||||
if (!newUserParams?.email) {
|
||||
): Promise<PartialUserWithPicture> {
|
||||
if (!newUserPayload?.email) {
|
||||
throw new AuthException(
|
||||
'Email is required',
|
||||
AuthExceptionCode.INVALID_INPUT,
|
||||
@@ -74,11 +71,22 @@ export class SignInUpService {
|
||||
);
|
||||
}
|
||||
|
||||
const partialNewUser: PartialUserWithPicture = {
|
||||
email: newUserPayload.email,
|
||||
firstName: newUserPayload.firstName ?? '',
|
||||
lastName: newUserPayload.lastName ?? '',
|
||||
picture: newUserPayload.picture ?? '',
|
||||
locale: newUserPayload.locale ?? 'en',
|
||||
isEmailVerified: newUserPayload.isEmailAlreadyVerified,
|
||||
};
|
||||
|
||||
if (authParams.provider === AuthProviderEnum.Password) {
|
||||
newUserParams.passwordHash = await this.generateHash(authParams.password);
|
||||
partialNewUser.passwordHash = await this.generateHash(
|
||||
authParams.password,
|
||||
);
|
||||
}
|
||||
|
||||
return newUserParams as PartialUserWithPicture;
|
||||
return partialNewUser;
|
||||
}
|
||||
|
||||
async signInUp(
|
||||
@@ -428,7 +436,7 @@ export class SignInUpService {
|
||||
authParams: AuthProviderWithPasswordType['authParams'],
|
||||
) {
|
||||
return this.saveNewUser(
|
||||
await this.computeParamsForNewUser(newUserParams, authParams),
|
||||
await this.computePartialUserFromUserPayload(newUserParams, authParams),
|
||||
await this.setDefaultImpersonateAndAccessFullAdminPanel(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ export type SignInUpNewUserPayload = {
|
||||
picture?: string | null;
|
||||
passwordHash?: string | null;
|
||||
locale?: keyof typeof APP_LOCALES | null;
|
||||
isEmailAlreadyVerified?: boolean;
|
||||
};
|
||||
|
||||
export type PartialUserWithPicture = {
|
||||
|
||||
Reference in New Issue
Block a user