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 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());
}
};