0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(core): fix empty error message (#3202)

This commit is contained in:
simeng-li 2023-02-24 10:17:33 +08:00 committed by GitHub
parent 0e9d851f68
commit af66760a42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,23 +4,24 @@ import { SignInMode, SignInIdentifier, InteractionEvent } from '@logto/schemas';
import RequestError from '#src/errors/RequestError/index.js'; import RequestError from '#src/errors/RequestError/index.js';
import assertThat from '#src/utils/assert-that.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({ const forbiddenIdentifierError = () =>
code: 'user.sign_in_method_not_enabled', new RequestError({
status: 422, code: 'user.sign_in_method_not_enabled',
}); status: 422,
});
export const verifySignInModeSettings = ( export const verifySignInModeSettings = (
event: InteractionEvent, event: InteractionEvent,
{ signInMode }: SignInExperience { signInMode }: SignInExperience
) => { ) => {
if (event === InteractionEvent.SignIn) { if (event === InteractionEvent.SignIn) {
assertThat(signInMode !== SignInMode.Register, forbiddenEventError); assertThat(signInMode !== SignInMode.Register, forbiddenEventError());
} }
if (event === InteractionEvent.Register) { if (event === InteractionEvent.Register) {
assertThat(signInMode !== SignInMode.SignIn, forbiddenEventError); assertThat(signInMode !== SignInMode.SignIn, forbiddenEventError());
} }
}; };
@ -36,7 +37,7 @@ export const verifyIdentifierSettings = (
signIn.methods.some( signIn.methods.some(
({ identifier: method, password }) => method === SignInIdentifier.Username && password ({ identifier: method, password }) => method === SignInIdentifier.Username && password
), ),
forbiddenIdentifierError forbiddenIdentifierError()
); );
return; return;
@ -67,7 +68,7 @@ export const verifyIdentifierSettings = (
return true; return true;
}), }),
forbiddenIdentifierError forbiddenIdentifierError()
); );
return; return;
@ -98,7 +99,7 @@ export const verifyIdentifierSettings = (
return true; return true;
}), }),
forbiddenIdentifierError forbiddenIdentifierError()
); );
} }
@ -107,18 +108,18 @@ export const verifyIdentifierSettings = (
export const verifyProfileSettings = (profile: Profile, { signUp }: SignInExperience) => { export const verifyProfileSettings = (profile: Profile, { signUp }: SignInExperience) => {
if (profile.phone) { if (profile.phone) {
assertThat(signUp.identifiers.includes(SignInIdentifier.Phone), forbiddenIdentifierError); assertThat(signUp.identifiers.includes(SignInIdentifier.Phone), forbiddenIdentifierError());
} }
if (profile.email) { if (profile.email) {
assertThat(signUp.identifiers.includes(SignInIdentifier.Email), forbiddenIdentifierError); assertThat(signUp.identifiers.includes(SignInIdentifier.Email), forbiddenIdentifierError());
} }
if (profile.username) { if (profile.username) {
assertThat(signUp.identifiers.includes(SignInIdentifier.Username), forbiddenIdentifierError); assertThat(signUp.identifiers.includes(SignInIdentifier.Username), forbiddenIdentifierError());
} }
if (profile.password) { if (profile.password) {
assertThat(signUp.password, forbiddenIdentifierError); assertThat(signUp.password, forbiddenIdentifierError());
} }
}; };