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:
parent
0e9d851f68
commit
af66760a42
1 changed files with 15 additions and 14 deletions
|
@ -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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue