0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-10 22:22:45 -05:00

fix(core): require connector when verification code is enabled (#2394)

This commit is contained in:
wangsijie 2022-11-11 10:33:33 +08:00 committed by GitHub
parent 2acc6da741
commit d99d67b9b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View file

@ -66,7 +66,7 @@ describe('validate sign-in', () => {
}); });
describe('There must be at least one enabled connector for the specific identifier.', () => { describe('There must be at least one enabled connector for the specific identifier.', () => {
it('throws when there is no enabled email connector and identifiers includes email', () => { it('throws when there is no enabled email connector and identifiers includes email with verification code checked', () => {
expect(() => { expect(() => {
validateSignIn( validateSignIn(
{ {
@ -74,6 +74,7 @@ describe('validate sign-in', () => {
{ {
...mockSignInMethod, ...mockSignInMethod,
identifier: SignInIdentifier.Email, identifier: SignInIdentifier.Email,
verificationCode: true,
}, },
], ],
}, },
@ -88,7 +89,7 @@ describe('validate sign-in', () => {
); );
}); });
it('throws when there is no enabled sms connector and identifiers includes phone', () => { it('throws when there is no enabled sms connector and identifiers includes phone with verification code checked', () => {
expect(() => { expect(() => {
validateSignIn( validateSignIn(
{ {
@ -96,6 +97,7 @@ describe('validate sign-in', () => {
{ {
...mockSignInMethod, ...mockSignInMethod,
identifier: SignInIdentifier.Sms, identifier: SignInIdentifier.Sms,
verificationCode: true,
}, },
], ],
}, },

View file

@ -11,7 +11,12 @@ export const validateSignIn = (
signUp: SignUp, signUp: SignUp,
enabledConnectors: LogtoConnector[] enabledConnectors: LogtoConnector[]
) => { ) => {
if (signIn.methods.some(({ identifier }) => identifier === SignInIdentifier.Email)) { if (
signIn.methods.some(
({ identifier, verificationCode }) =>
verificationCode && identifier === SignInIdentifier.Email
)
) {
assertThat( assertThat(
enabledConnectors.some((item) => item.type === ConnectorType.Email), enabledConnectors.some((item) => item.type === ConnectorType.Email),
new RequestError({ new RequestError({
@ -21,7 +26,11 @@ export const validateSignIn = (
); );
} }
if (signIn.methods.some(({ identifier }) => identifier === SignInIdentifier.Sms)) { if (
signIn.methods.some(
({ identifier, verificationCode }) => verificationCode && identifier === SignInIdentifier.Sms
)
) {
assertThat( assertThat(
enabledConnectors.some((item) => item.type === ConnectorType.Sms), enabledConnectors.some((item) => item.type === ConnectorType.Sms),
new RequestError({ new RequestError({