mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -05:00
fix(core): fix user password and identities check (#2379)
This commit is contained in:
parent
d99d67b9b2
commit
651436fbd9
2 changed files with 11 additions and 3 deletions
|
@ -23,6 +23,7 @@ import {
|
|||
getContinueSignInResult,
|
||||
getRoutePrefix,
|
||||
getVerificationStorageFromInteraction,
|
||||
isUserPasswordSet,
|
||||
} from './utils';
|
||||
|
||||
export const continueRoute = getRoutePrefix('sign-in', 'continue');
|
||||
|
@ -42,7 +43,7 @@ export default function continueRoutes<T extends AnonymousRouter>(router: T, pro
|
|||
|
||||
// Social identities can take place the role of password
|
||||
assertThat(
|
||||
!user.passwordEncrypted && Object.keys(user.identities).length === 0,
|
||||
!isUserPasswordSet(user),
|
||||
new RequestError({
|
||||
code: 'user.password_exists',
|
||||
})
|
||||
|
|
|
@ -152,6 +152,13 @@ export const getContinueSignInResult = async (
|
|||
return rest;
|
||||
};
|
||||
|
||||
export const isUserPasswordSet = ({
|
||||
passwordEncrypted,
|
||||
identities,
|
||||
}: Pick<User, 'passwordEncrypted' | 'identities'>): boolean => {
|
||||
return Boolean(passwordEncrypted) || Object.keys(identities).length > 0;
|
||||
};
|
||||
|
||||
/* eslint-disable complexity */
|
||||
export const checkRequiredProfile = async (
|
||||
ctx: Context,
|
||||
|
@ -160,11 +167,11 @@ export const checkRequiredProfile = async (
|
|||
signInExperience: SignInExperience
|
||||
) => {
|
||||
const { signUp } = signInExperience;
|
||||
const { passwordEncrypted, id, username, primaryEmail, primaryPhone } = user;
|
||||
const { id, username, primaryEmail, primaryPhone } = user;
|
||||
|
||||
// If check failed, save the sign in result, the user can continue after requirements are meet
|
||||
|
||||
if (signUp.password && !passwordEncrypted) {
|
||||
if (signUp.password && !isUserPasswordSet(user)) {
|
||||
await assignContinueSignInResult(ctx, provider, { userId: id });
|
||||
throw new RequestError({ code: 'user.require_password', status: 422 });
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue