diff --git a/packages/core/src/routes/interaction/utils/sign-in-experience-validation.ts b/packages/core/src/routes/interaction/utils/sign-in-experience-validation.ts index 3b60abadb..f8c113f4c 100644 --- a/packages/core/src/routes/interaction/utils/sign-in-experience-validation.ts +++ b/packages/core/src/routes/interaction/utils/sign-in-experience-validation.ts @@ -4,23 +4,24 @@ import { SignInMode, SignInIdentifier, InteractionEvent } from '@logto/schemas'; import RequestError from '#src/errors/RequestError/index.js'; import assertThat from '#src/utils/assert-that.js'; -const forbiddenEventError = new RequestError({ code: 'auth.forbidden', status: 403 }); +const forbiddenEventError = () => new RequestError({ code: 'auth.forbidden', status: 403 }); -const forbiddenIdentifierError = new RequestError({ - code: 'user.sign_in_method_not_enabled', - status: 422, -}); +const forbiddenIdentifierError = () => + new RequestError({ + code: 'user.sign_in_method_not_enabled', + status: 422, + }); export const verifySignInModeSettings = ( event: InteractionEvent, { signInMode }: SignInExperience ) => { if (event === InteractionEvent.SignIn) { - assertThat(signInMode !== SignInMode.Register, forbiddenEventError); + assertThat(signInMode !== SignInMode.Register, forbiddenEventError()); } if (event === InteractionEvent.Register) { - assertThat(signInMode !== SignInMode.SignIn, forbiddenEventError); + assertThat(signInMode !== SignInMode.SignIn, forbiddenEventError()); } }; @@ -36,7 +37,7 @@ export const verifyIdentifierSettings = ( signIn.methods.some( ({ identifier: method, password }) => method === SignInIdentifier.Username && password ), - forbiddenIdentifierError + forbiddenIdentifierError() ); return; @@ -67,7 +68,7 @@ export const verifyIdentifierSettings = ( return true; }), - forbiddenIdentifierError + forbiddenIdentifierError() ); return; @@ -98,7 +99,7 @@ export const verifyIdentifierSettings = ( return true; }), - forbiddenIdentifierError + forbiddenIdentifierError() ); } @@ -107,18 +108,18 @@ export const verifyIdentifierSettings = ( export const verifyProfileSettings = (profile: Profile, { signUp }: SignInExperience) => { if (profile.phone) { - assertThat(signUp.identifiers.includes(SignInIdentifier.Phone), forbiddenIdentifierError); + assertThat(signUp.identifiers.includes(SignInIdentifier.Phone), forbiddenIdentifierError()); } if (profile.email) { - assertThat(signUp.identifiers.includes(SignInIdentifier.Email), forbiddenIdentifierError); + assertThat(signUp.identifiers.includes(SignInIdentifier.Email), forbiddenIdentifierError()); } if (profile.username) { - assertThat(signUp.identifiers.includes(SignInIdentifier.Username), forbiddenIdentifierError); + assertThat(signUp.identifiers.includes(SignInIdentifier.Username), forbiddenIdentifierError()); } if (profile.password) { - assertThat(signUp.password, forbiddenIdentifierError); + assertThat(signUp.password, forbiddenIdentifierError()); } };