From 4af325af037db886dd064409cd8399a4259f2a37 Mon Sep 17 00:00:00 2001 From: simeng-li Date: Fri, 6 Jan 2023 17:43:28 +0800 Subject: [PATCH] refactor(core,ui,schemas): replace sms sign-in method with phone (#2825) --- .../console/src/hooks/use-connector-in-use.ts | 2 +- .../src/pages/SignInExperience/constants.ts | 6 +- .../SignInExperience/utils/identifier.ts | 4 +- .../core/src/__mocks__/sign-in-experience.ts | 2 +- .../sign-in-experience/sign-in.test.ts | 16 +- .../libraries/sign-in-experience/sign-in.ts | 7 +- .../sign-in-experience/sign-up.test.ts | 8 +- .../libraries/sign-in-experience/sign-up.ts | 4 +- .../sign-in-experience-valiation.test.ts | 20 +- .../utils/sign-in-experience-validation.ts | 6 +- .../mandatory-user-profile-validation.test.ts | 6 +- .../mandatory-user-profile-validation.ts | 4 +- .../session/middleware/passwordless-action.ts | 4 +- packages/core/src/routes/session/password.ts | 2 +- .../src/routes/session/passwordless.test.ts | 4 +- .../core/src/routes/session/utils.test.ts | 8 +- packages/core/src/routes/session/utils.ts | 4 +- packages/core/src/routes/well-known.ts | 2 +- packages/integration-tests/src/constants.ts | 4 +- .../api/interaction/forgot-password.test.ts | 2 +- .../register-with-identifier.test.ts | 6 +- .../sign-in-with-passcode-identifier.test.ts | 2 +- .../sign-in-with-password-identifier.test.ts | 2 +- .../interaction/utils/sign-in-experience.ts | 4 +- .../src/tests/api/session.test.ts | 2 +- packages/phrases-ui/src/locales/de.ts | 2 +- packages/phrases-ui/src/locales/en.ts | 2 +- packages/phrases-ui/src/locales/fr.ts | 2 +- packages/phrases-ui/src/locales/ko.ts | 2 +- packages/phrases-ui/src/locales/pt-br.ts | 2 +- packages/phrases-ui/src/locales/pt-pt.ts | 2 +- packages/phrases-ui/src/locales/tr-tr.ts | 2 +- packages/phrases-ui/src/locales/zh-cn.ts | 2 +- .../translation/admin-console/sign-in-exp.ts | 2 +- .../translation/admin-console/sign-in-exp.ts | 2 +- .../translation/admin-console/sign-in-exp.ts | 2 +- .../translation/admin-console/sign-in-exp.ts | 2 +- .../translation/admin-console/sign-in-exp.ts | 2 +- .../translation/admin-console/sign-in-exp.ts | 2 +- .../translation/admin-console/sign-in-exp.ts | 2 +- .../translation/admin-console/sign-in-exp.ts | 2 +- ...2907416-sms-sign-in-identifier-to-phone.ts | 184 ++++++++++++++++++ .../schemas/src/foundations/jsonb-types.ts | 2 +- packages/ui/src/App.tsx | 2 +- packages/ui/src/__mocks__/logto.tsx | 8 +- .../components/ForgotPasswordLink/index.tsx | 2 +- .../ui/src/containers/EmailForm/EmailForm.tsx | 2 +- .../ui/src/containers/EmailPassword/index.tsx | 2 +- .../src/containers/OtherMethodsLink/index.tsx | 2 +- .../PasscodeValidation/PasswordSignInLink.tsx | 6 +- .../PasscodeValidation/index.test.tsx | 22 ++- .../containers/PasscodeValidation/index.tsx | 2 +- ...continue-set-phone-passcode-validation.ts} | 6 +- ...got-password-phone-passcode-validation.ts} | 6 +- .../use-identifier-error-alert.ts | 2 +- ...egister-with-phone-passcode-validation.ts} | 12 +- .../PasscodeValidation/use-resend-passcode.ts | 2 +- ...sign-in-with-phone-passcode-validation.ts} | 12 +- .../containers/PasscodeValidation/utils.ts | 18 +- .../PasswordlessSignInLink.tsx | 2 +- .../PasswordSignInForm/index.test.tsx | 6 +- .../containers/PasswordSignInForm/index.tsx | 10 +- .../PasswordlessSwitch/index.test.tsx | 8 +- .../containers/PasswordlessSwitch/index.tsx | 2 +- ...ntinue.test.tsx => PhoneContinue.test.tsx} | 8 +- .../{SmsContinue.tsx => PhoneContinue.tsx} | 10 +- ...gister.test.tsx => PhoneRegister.test.tsx} | 8 +- .../{SmsRegister.tsx => PhoneRegister.tsx} | 6 +- ...d.test.tsx => PhoneResetPassword.test.tsx} | 8 +- ...setPassword.tsx => PhoneResetPassword.tsx} | 6 +- ...msSignIn.test.tsx => PhoneSignIn.test.tsx} | 36 ++-- .../{SmsSignIn.tsx => PhoneSignIn.tsx} | 16 +- .../ui/src/containers/PhoneForm/index.tsx | 8 +- .../ui/src/containers/PhonePassword/index.tsx | 4 +- .../containers/UsernameSignIn/index.test.tsx | 5 +- .../src/containers/UsernameSignIn/index.tsx | 2 +- .../use-continue-sign-in-with-password.ts | 2 +- .../src/hooks/use-passwordless-send-code.ts | 2 +- .../use-required-profile-error-handler.ts | 4 +- packages/ui/src/hooks/use-sie.ts | 2 +- .../Continue/EmailOrPhone/index.test.tsx | 8 +- .../src/pages/Continue/EmailOrPhone/index.tsx | 6 +- .../pages/Continue/SetPhone/index.test.tsx | 2 +- .../ui/src/pages/Continue/SetPhone/index.tsx | 4 +- packages/ui/src/pages/Continue/index.tsx | 2 +- .../src/pages/ForgotPassword/index.test.tsx | 16 +- .../ui/src/pages/ForgotPassword/index.tsx | 10 +- packages/ui/src/pages/Passcode/index.tsx | 3 +- packages/ui/src/pages/Register/Main.tsx | 6 +- packages/ui/src/pages/Register/index.test.tsx | 8 +- .../pages/SecondaryRegister/index.test.tsx | 4 +- .../ui/src/pages/SecondaryRegister/index.tsx | 6 +- .../src/pages/SecondarySignIn/index.test.tsx | 2 +- .../ui/src/pages/SecondarySignIn/index.tsx | 6 +- packages/ui/src/pages/SignIn/Main.tsx | 6 +- packages/ui/src/pages/SignIn/index.test.tsx | 8 +- .../src/pages/SignInPassword/index.test.tsx | 4 +- .../ui/src/pages/SignInPassword/index.tsx | 13 +- packages/ui/src/types/guard.ts | 6 +- packages/ui/src/types/index.ts | 2 +- packages/ui/src/utils/sign-in-experience.ts | 6 +- 101 files changed, 468 insertions(+), 270 deletions(-) create mode 100644 packages/schemas/alterations/next-1672907416-sms-sign-in-identifier-to-phone.ts rename packages/ui/src/containers/PasscodeValidation/{use-continue-set-sms-passcode-validation.ts => use-continue-set-phone-passcode-validation.ts} (90%) rename packages/ui/src/containers/PasscodeValidation/{use-forgot-password-sms-passcode-validation.ts => use-forgot-password-phone-passcode-validation.ts} (89%) rename packages/ui/src/containers/PasscodeValidation/{use-register-with-sms-passcode-validation.ts => use-register-with-phone-passcode-validation.ts} (89%) rename packages/ui/src/containers/PasscodeValidation/{use-sign-in-with-sms-passcode-validation.ts => use-sign-in-with-phone-passcode-validation.ts} (90%) rename packages/ui/src/containers/PhoneForm/{SmsContinue.test.tsx => PhoneContinue.test.tsx} (89%) rename packages/ui/src/containers/PhoneForm/{SmsContinue.tsx => PhoneContinue.tsx} (79%) rename packages/ui/src/containers/PhoneForm/{SmsRegister.test.tsx => PhoneRegister.test.tsx} (90%) rename packages/ui/src/containers/PhoneForm/{SmsRegister.tsx => PhoneRegister.tsx} (86%) rename packages/ui/src/containers/PhoneForm/{SmsResetPassword.test.tsx => PhoneResetPassword.test.tsx} (92%) rename packages/ui/src/containers/PhoneForm/{SmsResetPassword.tsx => PhoneResetPassword.tsx} (86%) rename packages/ui/src/containers/PhoneForm/{SmsSignIn.test.tsx => PhoneSignIn.test.tsx} (80%) rename packages/ui/src/containers/PhoneForm/{SmsSignIn.tsx => PhoneSignIn.tsx} (79%) diff --git a/packages/console/src/hooks/use-connector-in-use.ts b/packages/console/src/hooks/use-connector-in-use.ts index cf2481b25..766f2655d 100644 --- a/packages/console/src/hooks/use-connector-in-use.ts +++ b/packages/console/src/hooks/use-connector-in-use.ts @@ -21,7 +21,7 @@ const useConnectorInUse = () => { } const relatedIdentifier = - type === ConnectorType.Email ? SignInIdentifier.Email : SignInIdentifier.Sms; + type === ConnectorType.Email ? SignInIdentifier.Email : SignInIdentifier.Phone; const usedInSignUp = data.signUp.identifiers.includes(relatedIdentifier) && data.signUp.verify; diff --git a/packages/console/src/pages/SignInExperience/constants.ts b/packages/console/src/pages/SignInExperience/constants.ts index 0e42938e0..0493fe0c7 100644 --- a/packages/console/src/pages/SignInExperience/constants.ts +++ b/packages/console/src/pages/SignInExperience/constants.ts @@ -9,8 +9,8 @@ export const signInIdentifiers = Object.values(SignInIdentifier); export const signUpIdentifiersMapping: { [key in SignUpIdentifier]: SignInIdentifier[] } = { [SignUpIdentifier.Username]: [SignInIdentifier.Username], [SignUpIdentifier.Email]: [SignInIdentifier.Email], - [SignUpIdentifier.Sms]: [SignInIdentifier.Sms], - [SignUpIdentifier.EmailOrSms]: [SignInIdentifier.Email, SignInIdentifier.Sms], + [SignUpIdentifier.Sms]: [SignInIdentifier.Phone], + [SignUpIdentifier.EmailOrSms]: [SignInIdentifier.Email, SignInIdentifier.Phone], [SignUpIdentifier.None]: [], }; @@ -18,5 +18,5 @@ export const identifierRequiredConnectorMapping: { [key in SignInIdentifier]?: ConnectorType; } = { [SignInIdentifier.Email]: ConnectorType.Email, - [SignInIdentifier.Sms]: ConnectorType.Sms, + [SignInIdentifier.Phone]: ConnectorType.Sms, }; diff --git a/packages/console/src/pages/SignInExperience/utils/identifier.ts b/packages/console/src/pages/SignInExperience/utils/identifier.ts index 0fa1e80de..f92248dfd 100644 --- a/packages/console/src/pages/SignInExperience/utils/identifier.ts +++ b/packages/console/src/pages/SignInExperience/utils/identifier.ts @@ -8,7 +8,9 @@ import type { SignUpIdentifier } from '../types'; export const isVerificationRequiredSignUpIdentifiers = (signUpIdentifier: SignUpIdentifier) => { const identifiers = signUpIdentifiersMapping[signUpIdentifier]; - return identifiers.includes(SignInIdentifier.Email) || identifiers.includes(SignInIdentifier.Sms); + return ( + identifiers.includes(SignInIdentifier.Email) || identifiers.includes(SignInIdentifier.Phone) + ); }; export const mapIdentifiersToSignUpIdentifier = ( diff --git a/packages/core/src/__mocks__/sign-in-experience.ts b/packages/core/src/__mocks__/sign-in-experience.ts index f464aba13..6ead6e855 100644 --- a/packages/core/src/__mocks__/sign-in-experience.ts +++ b/packages/core/src/__mocks__/sign-in-experience.ts @@ -81,7 +81,7 @@ export const mockSignInExperience: SignInExperience = { isPasswordPrimary: true, }, { - identifier: SignInIdentifier.Sms, + identifier: SignInIdentifier.Phone, password: true, verificationCode: true, isPasswordPrimary: true, diff --git a/packages/core/src/libraries/sign-in-experience/sign-in.test.ts b/packages/core/src/libraries/sign-in-experience/sign-in.test.ts index 7531983bc..b3ccd89db 100644 --- a/packages/core/src/libraries/sign-in-experience/sign-in.test.ts +++ b/packages/core/src/libraries/sign-in-experience/sign-in.test.ts @@ -26,14 +26,14 @@ describe('validate sign-in', () => { }, { ...mockSignInMethod, - identifier: SignInIdentifier.Sms, + identifier: SignInIdentifier.Phone, verificationCode: true, }, ], }, { ...mockSignUp, - identifiers: [SignInIdentifier.Email, SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Email, SignInIdentifier.Phone], password: false, verify: true, }, @@ -96,7 +96,7 @@ describe('validate sign-in', () => { methods: [ { ...mockSignInMethod, - identifier: SignInIdentifier.Sms, + identifier: SignInIdentifier.Phone, verificationCode: true, }, ], @@ -121,7 +121,7 @@ describe('validate sign-in', () => { methods: [ { ...mockSignInMethod, - identifier: SignInIdentifier.Sms, + identifier: SignInIdentifier.Phone, }, ], }, @@ -175,7 +175,7 @@ describe('validate sign-in', () => { }, { ...mockSignUp, - identifiers: [SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Phone], }, enabledConnectors ); @@ -199,7 +199,7 @@ describe('validate sign-in', () => { }, { ...mockSignUp, - identifiers: [SignInIdentifier.Email, SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Email, SignInIdentifier.Phone], }, enabledConnectors ); @@ -278,7 +278,7 @@ describe('validate sign-in', () => { }, { ...mockSignInMethod, - identifier: SignInIdentifier.Sms, + identifier: SignInIdentifier.Phone, verificationCode: true, password: false, }, @@ -286,7 +286,7 @@ describe('validate sign-in', () => { }, { ...mockSignUp, - identifiers: [SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Phone], password: false, verify: true, }, diff --git a/packages/core/src/libraries/sign-in-experience/sign-in.ts b/packages/core/src/libraries/sign-in-experience/sign-in.ts index 3e9e52d3a..5803e11da 100644 --- a/packages/core/src/libraries/sign-in-experience/sign-in.ts +++ b/packages/core/src/libraries/sign-in-experience/sign-in.ts @@ -27,7 +27,8 @@ export const validateSignIn = ( if ( signIn.methods.some( - ({ identifier, verificationCode }) => verificationCode && identifier === SignInIdentifier.Sms + ({ identifier, verificationCode }) => + verificationCode && identifier === SignInIdentifier.Phone ) ) { assertThat( @@ -65,9 +66,9 @@ export const validateSignIn = ( ); } - if (identifier === SignInIdentifier.Sms) { + if (identifier === SignInIdentifier.Phone) { assertThat( - signIn.methods.some(({ identifier }) => identifier === SignInIdentifier.Sms), + signIn.methods.some(({ identifier }) => identifier === SignInIdentifier.Phone), new RequestError({ code: 'sign_in_experiences.miss_sign_up_identifier_in_sign_in', }) diff --git a/packages/core/src/libraries/sign-in-experience/sign-up.test.ts b/packages/core/src/libraries/sign-in-experience/sign-up.test.ts index c5367f8c3..ebfd56578 100644 --- a/packages/core/src/libraries/sign-in-experience/sign-up.test.ts +++ b/packages/core/src/libraries/sign-in-experience/sign-up.test.ts @@ -33,7 +33,7 @@ describe('validate sign-up', () => { validateSignUp( { ...mockSignUp, - identifiers: [SignInIdentifier.Email, SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Email, SignInIdentifier.Phone], }, [] ); @@ -47,7 +47,7 @@ describe('validate sign-up', () => { test('should throw when there is no sms connector and identifier is phone', async () => { expect(() => { - validateSignUp({ ...mockSignUp, identifiers: [SignInIdentifier.Sms] }, []); + validateSignUp({ ...mockSignUp, identifiers: [SignInIdentifier.Phone] }, []); }).toMatchError( new RequestError({ code: 'sign_in_experiences.enabled_connector_not_found', @@ -62,7 +62,7 @@ describe('validate sign-up', () => { { ...mockSignUp, verify: true, - identifiers: [SignInIdentifier.Email, SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Email, SignInIdentifier.Phone], }, [mockAliyunSmsConnector] ); @@ -120,7 +120,7 @@ describe('validate sign-up', () => { validateSignUp( { ...mockSignUp, - identifiers: [SignInIdentifier.Email, SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Email, SignInIdentifier.Phone], verify: false, }, enabledConnectors diff --git a/packages/core/src/libraries/sign-in-experience/sign-up.ts b/packages/core/src/libraries/sign-in-experience/sign-up.ts index 601fc0cda..45c3ff49e 100644 --- a/packages/core/src/libraries/sign-in-experience/sign-up.ts +++ b/packages/core/src/libraries/sign-in-experience/sign-up.ts @@ -17,7 +17,7 @@ export const validateSignUp = (signUp: SignUp, enabledConnectors: LogtoConnector ); } - if (identifier === SignInIdentifier.Sms) { + if (identifier === SignInIdentifier.Phone) { assertThat( enabledConnectors.some((item) => item.type === ConnectorType.Sms), new RequestError({ @@ -36,7 +36,7 @@ export const validateSignUp = (signUp: SignUp, enabledConnectors: LogtoConnector ); } - if (identifier === SignInIdentifier.Email || identifier === SignInIdentifier.Sms) { + if (identifier === SignInIdentifier.Email || identifier === SignInIdentifier.Phone) { assertThat( signUp.verify, new RequestError({ diff --git a/packages/core/src/routes/interaction/utils/sign-in-experience-valiation.test.ts b/packages/core/src/routes/interaction/utils/sign-in-experience-valiation.test.ts index e75848791..e77529ad3 100644 --- a/packages/core/src/routes/interaction/utils/sign-in-experience-valiation.test.ts +++ b/packages/core/src/routes/interaction/utils/sign-in-experience-valiation.test.ts @@ -188,7 +188,7 @@ describe('identifier validation', () => { ...mockSignInExperience, signIn: { methods: mockSignInExperience.signIn.methods.filter( - ({ identifier }) => identifier !== SignInIdentifier.Sms + ({ identifier }) => identifier !== SignInIdentifier.Phone ), }, }); @@ -200,7 +200,7 @@ describe('identifier validation', () => { signIn: { methods: [ { - identifier: SignInIdentifier.Sms, + identifier: SignInIdentifier.Phone, password: false, verificationCode: true, isPasswordPrimary: true, @@ -223,7 +223,7 @@ describe('identifier validation', () => { ...mockSignInExperience, signIn: { methods: mockSignInExperience.signIn.methods.filter( - ({ identifier }) => identifier !== SignInIdentifier.Sms + ({ identifier }) => identifier !== SignInIdentifier.Phone ), }, }); @@ -235,7 +235,7 @@ describe('identifier validation', () => { signIn: { methods: [ { - identifier: SignInIdentifier.Sms, + identifier: SignInIdentifier.Phone, password: true, verificationCode: false, isPasswordPrimary: true, @@ -249,14 +249,14 @@ describe('identifier validation', () => { verifyIdentifierSettings(identifier, { ...mockSignInExperience, signUp: { - identifiers: [SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Phone], password: false, verify: true, }, signIn: { methods: [ { - identifier: SignInIdentifier.Sms, + identifier: SignInIdentifier.Phone, password: true, verificationCode: false, isPasswordPrimary: true, @@ -297,7 +297,7 @@ describe('profile validation', () => { { phone: '123456' }, { ...mockSignInExperience, - signUp: { identifiers: [SignInIdentifier.Sms], password: false, verify: true }, + signUp: { identifiers: [SignInIdentifier.Phone], password: false, verify: true }, } ); }).not.toThrow(); @@ -308,7 +308,7 @@ describe('profile validation', () => { { ...mockSignInExperience, signUp: { - identifiers: [SignInIdentifier.Sms, SignInIdentifier.Email], + identifiers: [SignInIdentifier.Phone, SignInIdentifier.Email], password: false, verify: true, }, @@ -322,7 +322,7 @@ describe('profile validation', () => { { ...mockSignInExperience, signUp: { - identifiers: [SignInIdentifier.Sms, SignInIdentifier.Email], + identifiers: [SignInIdentifier.Phone, SignInIdentifier.Email], password: false, verify: true, }, @@ -336,7 +336,7 @@ describe('profile validation', () => { { ...mockSignInExperience, signUp: { - identifiers: [SignInIdentifier.Sms, SignInIdentifier.Email], + identifiers: [SignInIdentifier.Phone, SignInIdentifier.Email], password: false, verify: true, }, 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 ee4a7d9e3..dc589042a 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 @@ -77,7 +77,7 @@ export const verifyIdentifierSettings = ( if ('phone' in identifier) { assertThat( signIn.methods.some(({ identifier: method, password, verificationCode }) => { - if (method !== SignInIdentifier.Sms) { + if (method !== SignInIdentifier.Phone) { return false; } @@ -90,7 +90,7 @@ export const verifyIdentifierSettings = ( if ( 'passcode' in identifier && !verificationCode && - !signUp.identifiers.includes(SignInIdentifier.Sms) && + !signUp.identifiers.includes(SignInIdentifier.Phone) && !signUp.verify ) { return false; @@ -107,7 +107,7 @@ export const verifyIdentifierSettings = ( export const verifyProfileSettings = (profile: Profile, { signUp }: SignInExperience) => { if (profile.phone) { - assertThat(signUp.identifiers.includes(SignInIdentifier.Sms), forbiddenIdentifierError); + assertThat(signUp.identifiers.includes(SignInIdentifier.Phone), forbiddenIdentifierError); } if (profile.email) { diff --git a/packages/core/src/routes/interaction/verifications/mandatory-user-profile-validation.test.ts b/packages/core/src/routes/interaction/verifications/mandatory-user-profile-validation.test.ts index d408c0da7..1c7ab1c71 100644 --- a/packages/core/src/routes/interaction/verifications/mandatory-user-profile-validation.test.ts +++ b/packages/core/src/routes/interaction/verifications/mandatory-user-profile-validation.test.ts @@ -114,7 +114,7 @@ describe('validateMandatoryUserProfile', () => { ...baseCtx, signInExperience: { ...mockSignInExperience, - signUp: { identifiers: [SignInIdentifier.Sms], password: false, verify: true }, + signUp: { identifiers: [SignInIdentifier.Phone], password: false, verify: true }, }, }; @@ -135,7 +135,7 @@ describe('validateMandatoryUserProfile', () => { ...baseCtx, signInExperience: { ...mockSignInExperience, - signUp: { identifiers: [SignInIdentifier.Sms], password: false, verify: true }, + signUp: { identifiers: [SignInIdentifier.Phone], password: false, verify: true }, }, }; @@ -148,7 +148,7 @@ describe('validateMandatoryUserProfile', () => { signInExperience: { ...mockSignInExperience, signUp: { - identifiers: [SignInIdentifier.Email, SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Email, SignInIdentifier.Phone], password: false, verify: true, }, diff --git a/packages/core/src/routes/interaction/verifications/mandatory-user-profile-validation.ts b/packages/core/src/routes/interaction/verifications/mandatory-user-profile-validation.ts index 5c7856c13..9b6e616d6 100644 --- a/packages/core/src/routes/interaction/verifications/mandatory-user-profile-validation.ts +++ b/packages/core/src/routes/interaction/verifications/mandatory-user-profile-validation.ts @@ -49,7 +49,7 @@ const getMissingProfileBySignUpIdentifiers = ({ // Email or phone if ( signUpIdentifiersSet.has(SignInIdentifier.Email) && - signUpIdentifiersSet.has(SignInIdentifier.Sms) + signUpIdentifiersSet.has(SignInIdentifier.Phone) ) { if (!user?.primaryPhone && !user?.primaryEmail && !profile?.phone && !profile?.email) { missingProfile.add(MissingProfile.emailOrPhone); @@ -66,7 +66,7 @@ const getMissingProfileBySignUpIdentifiers = ({ } // Phone only - if (signUpIdentifiersSet.has(SignInIdentifier.Sms) && !user?.primaryPhone && !profile?.phone) { + if (signUpIdentifiersSet.has(SignInIdentifier.Phone) && !user?.primaryPhone && !profile?.phone) { missingProfile.add(MissingProfile.phone); return missingProfile; diff --git a/packages/core/src/routes/session/middleware/passwordless-action.ts b/packages/core/src/routes/session/middleware/passwordless-action.ts index 617b60a43..939b88a35 100644 --- a/packages/core/src/routes/session/middleware/passwordless-action.ts +++ b/packages/core/src/routes/session/middleware/passwordless-action.ts @@ -38,7 +38,7 @@ export const smsSignInAction = - identifier === SignInIdentifier.Sms && verificationCode + identifier === SignInIdentifier.Phone && verificationCode ), new RequestError({ code: 'user.sign_in_method_not_enabled', @@ -127,7 +127,7 @@ export const smsRegisterAction = ( const { phone, password } = ctx.guard.body; const type = 'SignInSmsPassword'; await signInWithPassword(ctx, provider, { - identifier: SignInIdentifier.Sms, + identifier: SignInIdentifier.Phone, password, logType: type, logPayload: { phone }, diff --git a/packages/core/src/routes/session/passwordless.test.ts b/packages/core/src/routes/session/passwordless.test.ts index ba2798a98..0defabeda 100644 --- a/packages/core/src/routes/session/passwordless.test.ts +++ b/packages/core/src/routes/session/passwordless.test.ts @@ -711,7 +711,7 @@ describe('session -> passwordlessRoutes', () => { ...mockSignInExperience, signUp: { ...mockSignInExperience.signUp, - identifiers: [SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Phone], password: false, }, }); @@ -952,7 +952,7 @@ describe('session -> passwordlessRoutes', () => { ...mockSignInExperience, signUp: { ...mockSignInExperience.signUp, - identifiers: [SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Phone], }, }); diff --git a/packages/core/src/routes/session/utils.test.ts b/packages/core/src/routes/session/utils.test.ts index 44d9fdafa..6228e396b 100644 --- a/packages/core/src/routes/session/utils.test.ts +++ b/packages/core/src/routes/session/utils.test.ts @@ -216,7 +216,7 @@ describe('checkRequiredProfile', () => { ...mockSignInExperience, signUp: { ...mockSignInExperience.signUp, - identifiers: [SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Phone], password: true, verify: true, }, @@ -245,7 +245,7 @@ describe('checkRequiredProfile', () => { ...mockSignInExperience, signUp: { ...mockSignInExperience.signUp, - identifiers: [SignInIdentifier.Email, SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Email, SignInIdentifier.Phone], password: true, verify: true, }, @@ -275,7 +275,7 @@ describe('checkRequiredProfile', () => { ...mockSignInExperience, signUp: { ...mockSignInExperience.signUp, - identifiers: [SignInIdentifier.Email, SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Email, SignInIdentifier.Phone], password: true, verify: true, }, @@ -357,7 +357,7 @@ describe('signInWithPassword()', () => { methods: [ { ...mockSignInMethod, - identifier: SignInIdentifier.Sms, + identifier: SignInIdentifier.Phone, password: false, }, ], diff --git a/packages/core/src/routes/session/utils.ts b/packages/core/src/routes/session/utils.ts index 4030626f6..7696e948d 100644 --- a/packages/core/src/routes/session/utils.ts +++ b/packages/core/src/routes/session/utils.ts @@ -190,13 +190,13 @@ export const checkRequiredProfile = async ( throw new RequestError({ code: 'user.email_required_in_profile', status: 422 }); } - if (isSameArray(signUp.identifiers, [SignInIdentifier.Sms]) && !primaryPhone) { + if (isSameArray(signUp.identifiers, [SignInIdentifier.Phone]) && !primaryPhone) { await assignContinueSignInResult(ctx, provider, { userId: id }); throw new RequestError({ code: 'user.phone_required_in_profile', status: 422 }); } if ( - isSameArray(signUp.identifiers, [SignInIdentifier.Email, SignInIdentifier.Sms]) && + isSameArray(signUp.identifiers, [SignInIdentifier.Email, SignInIdentifier.Phone]) && !primaryEmail && !primaryPhone ) { diff --git a/packages/core/src/routes/well-known.ts b/packages/core/src/routes/well-known.ts index b39b57b73..e06ea47d0 100644 --- a/packages/core/src/routes/well-known.ts +++ b/packages/core/src/routes/well-known.ts @@ -22,7 +22,7 @@ export default function wellKnownRoutes(router: T, pr ]); const forgotPassword = { - sms: logtoConnectors.some(({ type }) => type === ConnectorType.Sms), + phone: logtoConnectors.some(({ type }) => type === ConnectorType.Sms), email: logtoConnectors.some(({ type }) => type === ConnectorType.Email), }; diff --git a/packages/integration-tests/src/constants.ts b/packages/integration-tests/src/constants.ts index 141cbcef0..e02fe489c 100644 --- a/packages/integration-tests/src/constants.ts +++ b/packages/integration-tests/src/constants.ts @@ -11,7 +11,7 @@ export const adminConsoleRedirectUri = `${logtoUrl}/console/callback`; export const signUpIdentifiers = { username: [SignInIdentifier.Username], email: [SignInIdentifier.Email], - sms: [SignInIdentifier.Sms], - emailOrSms: [SignInIdentifier.Email, SignInIdentifier.Sms], + sms: [SignInIdentifier.Phone], + emailOrSms: [SignInIdentifier.Email, SignInIdentifier.Phone], none: [], }; diff --git a/packages/integration-tests/src/tests/api/interaction/forgot-password.test.ts b/packages/integration-tests/src/tests/api/interaction/forgot-password.test.ts index 3e848f137..5ef9ab47e 100644 --- a/packages/integration-tests/src/tests/api/interaction/forgot-password.test.ts +++ b/packages/integration-tests/src/tests/api/interaction/forgot-password.test.ts @@ -22,7 +22,7 @@ describe('reset password', () => { await setEmailConnector(); await setSmsConnector(); await enableAllPasscodeSignInMethods({ - identifiers: [SignInIdentifier.Email, SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Email, SignInIdentifier.Phone], password: true, verify: true, }); diff --git a/packages/integration-tests/src/tests/api/interaction/register-with-identifier.test.ts b/packages/integration-tests/src/tests/api/interaction/register-with-identifier.test.ts index 811f27379..c519c9586 100644 --- a/packages/integration-tests/src/tests/api/interaction/register-with-identifier.test.ts +++ b/packages/integration-tests/src/tests/api/interaction/register-with-identifier.test.ts @@ -164,7 +164,7 @@ describe('Register with passwordless identifier', () => { it('register with phone', async () => { await enableAllPasscodeSignInMethods({ - identifiers: [SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Phone], password: false, verify: true, }); @@ -207,7 +207,7 @@ describe('Register with passwordless identifier', () => { it('register with phone and fulfill password', async () => { await enableAllPasscodeSignInMethods({ - identifiers: [SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Phone], password: true, verify: true, }); @@ -323,7 +323,7 @@ describe('Register with passwordless identifier', () => { } = await generateNewUser({ primaryPhone: true }); await enableAllPasscodeSignInMethods({ - identifiers: [SignInIdentifier.Sms], + identifiers: [SignInIdentifier.Phone], password: false, verify: true, }); diff --git a/packages/integration-tests/src/tests/api/interaction/sign-in-with-passcode-identifier.test.ts b/packages/integration-tests/src/tests/api/interaction/sign-in-with-passcode-identifier.test.ts index 952402cfe..2ae5b5084 100644 --- a/packages/integration-tests/src/tests/api/interaction/sign-in-with-passcode-identifier.test.ts +++ b/packages/integration-tests/src/tests/api/interaction/sign-in-with-passcode-identifier.test.ts @@ -138,7 +138,7 @@ describe('Sign-In flow using passcode identifiers', () => { // Enable phone sign-up await updateSignInExperience({ - signUp: { identifiers: [SignInIdentifier.Sms], password: false, verify: true }, + signUp: { identifiers: [SignInIdentifier.Phone], password: false, verify: true }, }); const client = await initClient(); diff --git a/packages/integration-tests/src/tests/api/interaction/sign-in-with-password-identifier.test.ts b/packages/integration-tests/src/tests/api/interaction/sign-in-with-password-identifier.test.ts index 1f29fd2da..cbb43c1aa 100644 --- a/packages/integration-tests/src/tests/api/interaction/sign-in-with-password-identifier.test.ts +++ b/packages/integration-tests/src/tests/api/interaction/sign-in-with-password-identifier.test.ts @@ -151,7 +151,7 @@ describe('Sign-In flow using password identifiers', () => { // Fulfill the phone number it('sign-in with username and password and fulfill the phone number', async () => { await enableAllPasscodeSignInMethods({ - identifiers: [SignInIdentifier.Sms, SignInIdentifier.Email], + identifiers: [SignInIdentifier.Phone, SignInIdentifier.Email], password: true, verify: true, }); diff --git a/packages/integration-tests/src/tests/api/interaction/utils/sign-in-experience.ts b/packages/integration-tests/src/tests/api/interaction/utils/sign-in-experience.ts index 0860156be..6eeaee62d 100644 --- a/packages/integration-tests/src/tests/api/interaction/utils/sign-in-experience.ts +++ b/packages/integration-tests/src/tests/api/interaction/utils/sign-in-experience.ts @@ -23,7 +23,7 @@ const defaultPasswordSignInMethods = [ isPasswordPrimary: false, }, { - identifier: SignInIdentifier.Sms, + identifier: SignInIdentifier.Phone, password: true, verificationCode: false, isPasswordPrimary: false, @@ -44,7 +44,7 @@ const defaultPasscodeSignInMethods = [ isPasswordPrimary: false, }, { - identifier: SignInIdentifier.Sms, + identifier: SignInIdentifier.Phone, password: true, verificationCode: true, isPasswordPrimary: false, diff --git a/packages/integration-tests/src/tests/api/session.test.ts b/packages/integration-tests/src/tests/api/session.test.ts index 5b05446ba..c1e507def 100644 --- a/packages/integration-tests/src/tests/api/session.test.ts +++ b/packages/integration-tests/src/tests/api/session.test.ts @@ -215,7 +215,7 @@ describe('sms passwordless flow', () => { isPasswordPrimary: true, }, { - identifier: SignInIdentifier.Sms, + identifier: SignInIdentifier.Phone, password: false, verificationCode: true, isPasswordPrimary: false, diff --git a/packages/phrases-ui/src/locales/de.ts b/packages/phrases-ui/src/locales/de.ts index 278689816..6937ec256 100644 --- a/packages/phrases-ui/src/locales/de.ts +++ b/packages/phrases-ui/src/locales/de.ts @@ -63,7 +63,7 @@ const translation = { reset_password: 'Passwort zurücksetzen', reset_password_description_email: 'Gib die Email Adresse deines Kontos ein und wir senden dir einen Bestätigungscode um dein Passwort zurückzusetzen.', - reset_password_description_sms: + reset_password_description_phone: 'Gib die Telefonnummer deines Kontos ein und wir senden dir einen Bestätigungscode um dein Passwort zurückzusetzen.', new_password: 'Neues Passwort', set_password: 'Set password', // UNTRANSLATED diff --git a/packages/phrases-ui/src/locales/en.ts b/packages/phrases-ui/src/locales/en.ts index 5265e4cfc..89ec552d0 100644 --- a/packages/phrases-ui/src/locales/en.ts +++ b/packages/phrases-ui/src/locales/en.ts @@ -59,7 +59,7 @@ const translation = { reset_password: 'Reset password', reset_password_description_email: 'Enter the email address associated with your account, and we’ll email you the verification code to reset your password.', - reset_password_description_sms: + reset_password_description_phone: 'Enter the phone number associated with your account, and we’ll message you the verification code to reset your password.', new_password: 'New password', set_password: 'Set password', diff --git a/packages/phrases-ui/src/locales/fr.ts b/packages/phrases-ui/src/locales/fr.ts index 19fde7510..207088506 100644 --- a/packages/phrases-ui/src/locales/fr.ts +++ b/packages/phrases-ui/src/locales/fr.ts @@ -63,7 +63,7 @@ const translation = { reset_password: 'Réinitialiser le mot de passe', reset_password_description_email: "Entrez l'adresse e-mail associée à votre compte et nous vous enverrons par e-mail le code de vérification pour réinitialiser votre mot de passe.", - reset_password_description_sms: + reset_password_description_phone: 'Entrez le numéro de téléphone associé à votre compte et nous vous enverrons le code de vérification par SMS pour réinitialiser votre mot de passe.', new_password: 'Nouveau mot de passe', set_password: 'Set password', // UNTRANSLATED diff --git a/packages/phrases-ui/src/locales/ko.ts b/packages/phrases-ui/src/locales/ko.ts index ad61bf854..0e758f1bd 100644 --- a/packages/phrases-ui/src/locales/ko.ts +++ b/packages/phrases-ui/src/locales/ko.ts @@ -59,7 +59,7 @@ const translation = { reset_password: '암호를 재설정', reset_password_description_email: '계정과 연결된 이메일 주소를 입력하면 비밀번호 재설정을 위한 인증 코드를 이메일로 보내드립니다.', - reset_password_description_sms: + reset_password_description_phone: '계정과 연결된 전화번호를 입력하면 비밀번호 재설정을 위한 인증 코드를 문자로 보내드립니다.', new_password: '새 비밀번호', set_password: '비밀번호 설정', diff --git a/packages/phrases-ui/src/locales/pt-br.ts b/packages/phrases-ui/src/locales/pt-br.ts index b8ed37aae..71c49e502 100644 --- a/packages/phrases-ui/src/locales/pt-br.ts +++ b/packages/phrases-ui/src/locales/pt-br.ts @@ -61,7 +61,7 @@ const translation = { reset_password: 'Redefinir senha', reset_password_description_email: 'Digite o endereço de e-mail associado à sua conta e enviaremos por e-mail o código de verificação para redefinir sua senha.', - reset_password_description_sms: + reset_password_description_phone: 'Digite o número de telefone associado à sua conta e enviaremos a você o código de verificação para redefinir sua senha.', new_password: 'Nova senha', set_password: 'Configurar senha', diff --git a/packages/phrases-ui/src/locales/pt-pt.ts b/packages/phrases-ui/src/locales/pt-pt.ts index 7e04585e2..dd6f4d8ed 100644 --- a/packages/phrases-ui/src/locales/pt-pt.ts +++ b/packages/phrases-ui/src/locales/pt-pt.ts @@ -59,7 +59,7 @@ const translation = { reset_password: 'Redefinir Password', reset_password_description_email: 'Digite o endereço de email associado à sua conta e enviaremos um email com o código de verificação para redefinir sua senha.', - reset_password_description_sms: + reset_password_description_phone: 'Digite o número de telefone associado à sua conta e enviaremos uma mensagem de texto com o código de verificação para redefinir sua senha.', new_password: 'Nova Senha', set_password: 'Set password', // UNTRANSLATED diff --git a/packages/phrases-ui/src/locales/tr-tr.ts b/packages/phrases-ui/src/locales/tr-tr.ts index cfeb17f53..722114298 100644 --- a/packages/phrases-ui/src/locales/tr-tr.ts +++ b/packages/phrases-ui/src/locales/tr-tr.ts @@ -60,7 +60,7 @@ const translation = { reset_password: 'Şifre yenile', reset_password_description_email: 'Hesabınızla ilişkili e-posta adresini girin, şifrenizi sıfırlamak için size doğrulama kodunu e-posta ile gönderelim.', - reset_password_description_sms: + reset_password_description_phone: 'Hesabınızla ilişkili telefon numarasını girin, şifrenizi sıfırlamak için size doğrulama kodunu kısa mesajla gönderelim.', new_password: 'Yeni Şifre', set_password: 'Set password', // UNTRANSLATED diff --git a/packages/phrases-ui/src/locales/zh-cn.ts b/packages/phrases-ui/src/locales/zh-cn.ts index 09f2695bc..b45453cfe 100644 --- a/packages/phrases-ui/src/locales/zh-cn.ts +++ b/packages/phrases-ui/src/locales/zh-cn.ts @@ -58,7 +58,7 @@ const translation = { social_bind_with_existing: '找到了一个匹配的帐号,你可以直接绑定。', reset_password: '重设密码', reset_password_description_email: '输入邮件地址,领取验证码以重设密码。', - reset_password_description_sms: '输入手机号,领取验证码以重设密码。', + reset_password_description_phone: '输入手机号,领取验证码以重设密码。', new_password: '新密码', set_password: '设置密码', password_changed: '已重置密码!', diff --git a/packages/phrases/src/locales/de/translation/admin-console/sign-in-exp.ts b/packages/phrases/src/locales/de/translation/admin-console/sign-in-exp.ts index a7ccca366..19be51fb8 100644 --- a/packages/phrases/src/locales/de/translation/admin-console/sign-in-exp.ts +++ b/packages/phrases/src/locales/de/translation/admin-console/sign-in-exp.ts @@ -18,7 +18,7 @@ const sign_in_exp = { sign_up_and_sign_in: { identifiers: 'Sign-up identifiers', // UNTRANSLATED identifiers_email: 'Email address', // UNTRANSLATED - identifiers_sms: 'Phone number', // UNTRANSLATED + identifiers_phone: 'Phone number', // UNTRANSLATED identifiers_username: 'Username', // UNTRANSLATED identifiers_email_or_sms: 'Email address or phone number', // UNTRANSLATED identifiers_none: 'Not applicable', // UNTRANSLATED diff --git a/packages/phrases/src/locales/en/translation/admin-console/sign-in-exp.ts b/packages/phrases/src/locales/en/translation/admin-console/sign-in-exp.ts index 819f8ddbb..407ae3780 100644 --- a/packages/phrases/src/locales/en/translation/admin-console/sign-in-exp.ts +++ b/packages/phrases/src/locales/en/translation/admin-console/sign-in-exp.ts @@ -40,7 +40,7 @@ const sign_in_exp = { sign_up_and_sign_in: { identifiers: 'Sign-up identifiers', identifiers_email: 'Email address', - identifiers_sms: 'Phone number', + identifiers_phone: 'Phone number', identifiers_username: 'Username', identifiers_email_or_sms: 'Email address or phone number', identifiers_none: 'Not applicable', diff --git a/packages/phrases/src/locales/fr/translation/admin-console/sign-in-exp.ts b/packages/phrases/src/locales/fr/translation/admin-console/sign-in-exp.ts index 633aee1ee..5f92cf9a7 100644 --- a/packages/phrases/src/locales/fr/translation/admin-console/sign-in-exp.ts +++ b/packages/phrases/src/locales/fr/translation/admin-console/sign-in-exp.ts @@ -42,7 +42,7 @@ const sign_in_exp = { sign_up_and_sign_in: { identifiers: 'Sign-up identifiers', // UNTRANSLATED identifiers_email: 'Email address', // UNTRANSLATED - identifiers_sms: 'Phone number', // UNTRANSLATED + identifiers_phone: 'Phone number', // UNTRANSLATED identifiers_username: 'Username', // UNTRANSLATED identifiers_email_or_sms: 'Email address or phone number', // UNTRANSLATED identifiers_none: 'Not applicable', // UNTRANSLATED diff --git a/packages/phrases/src/locales/ko/translation/admin-console/sign-in-exp.ts b/packages/phrases/src/locales/ko/translation/admin-console/sign-in-exp.ts index e99ab66b7..60dce6269 100644 --- a/packages/phrases/src/locales/ko/translation/admin-console/sign-in-exp.ts +++ b/packages/phrases/src/locales/ko/translation/admin-console/sign-in-exp.ts @@ -37,7 +37,7 @@ const sign_in_exp = { sign_up_and_sign_in: { identifiers: '회원가입 ID', identifiers_email: '이메일 주소', - identifiers_sms: '휴대전화번호', + identifiers_phone: '휴대전화번호', identifiers_username: '사용자 이름', identifiers_email_or_sms: '이메일 주소 또는 휴대전화번호', identifiers_none: '해당없음', diff --git a/packages/phrases/src/locales/pt-br/translation/admin-console/sign-in-exp.ts b/packages/phrases/src/locales/pt-br/translation/admin-console/sign-in-exp.ts index 7b0fa2396..e4f583d64 100644 --- a/packages/phrases/src/locales/pt-br/translation/admin-console/sign-in-exp.ts +++ b/packages/phrases/src/locales/pt-br/translation/admin-console/sign-in-exp.ts @@ -41,7 +41,7 @@ const sign_in_exp = { sign_up_and_sign_in: { identifiers: 'Identificadores de inscrição', identifiers_email: 'Endereço de e-mail', - identifiers_sms: 'Número de telefone', + identifiers_phone: 'Número de telefone', identifiers_username: 'Nome de usuário', identifiers_email_or_sms: 'Endereço de e-mail ou número de telefone', identifiers_none: 'Não aplicável', diff --git a/packages/phrases/src/locales/pt-pt/translation/admin-console/sign-in-exp.ts b/packages/phrases/src/locales/pt-pt/translation/admin-console/sign-in-exp.ts index 76ebed176..bf1c3d880 100644 --- a/packages/phrases/src/locales/pt-pt/translation/admin-console/sign-in-exp.ts +++ b/packages/phrases/src/locales/pt-pt/translation/admin-console/sign-in-exp.ts @@ -40,7 +40,7 @@ const sign_in_exp = { sign_up_and_sign_in: { identifiers: 'Sign-up identifiers', // UNTRANSLATED identifiers_email: 'Email address', // UNTRANSLATED - identifiers_sms: 'Phone number', // UNTRANSLATED + identifiers_phone: 'Phone number', // UNTRANSLATED identifiers_username: 'Username', // UNTRANSLATED identifiers_email_or_sms: 'Email address or phone number', // UNTRANSLATED identifiers_none: 'Not applicable', // UNTRANSLATED diff --git a/packages/phrases/src/locales/tr-tr/translation/admin-console/sign-in-exp.ts b/packages/phrases/src/locales/tr-tr/translation/admin-console/sign-in-exp.ts index ca50061db..ed1143594 100644 --- a/packages/phrases/src/locales/tr-tr/translation/admin-console/sign-in-exp.ts +++ b/packages/phrases/src/locales/tr-tr/translation/admin-console/sign-in-exp.ts @@ -41,7 +41,7 @@ const sign_in_exp = { sign_up_and_sign_in: { identifiers: 'Sign-up identifiers', // UNTRANSLATED identifiers_email: 'Email address', // UNTRANSLATED - identifiers_sms: 'Phone number', // UNTRANSLATED + identifiers_phone: 'Phone number', // UNTRANSLATED identifiers_username: 'Username', // UNTRANSLATED identifiers_email_or_sms: 'Email address or phone number', // UNTRANSLATED identifiers_none: 'Not applicable', // UNTRANSLATED diff --git a/packages/phrases/src/locales/zh-cn/translation/admin-console/sign-in-exp.ts b/packages/phrases/src/locales/zh-cn/translation/admin-console/sign-in-exp.ts index 92c5ee972..4eb35f579 100644 --- a/packages/phrases/src/locales/zh-cn/translation/admin-console/sign-in-exp.ts +++ b/packages/phrases/src/locales/zh-cn/translation/admin-console/sign-in-exp.ts @@ -38,7 +38,7 @@ const sign_in_exp = { sign_up_and_sign_in: { identifiers: '注册标识', identifiers_email: '邮件地址', - identifiers_sms: '手机号码', + identifiers_phone: '手机号码', identifiers_username: '用户名', identifiers_email_or_sms: '邮件地址或手机号码', identifiers_none: '无', diff --git a/packages/schemas/alterations/next-1672907416-sms-sign-in-identifier-to-phone.ts b/packages/schemas/alterations/next-1672907416-sms-sign-in-identifier-to-phone.ts new file mode 100644 index 000000000..859e8f743 --- /dev/null +++ b/packages/schemas/alterations/next-1672907416-sms-sign-in-identifier-to-phone.ts @@ -0,0 +1,184 @@ +import { sql } from 'slonik'; + +import type { AlterationScript } from '../lib/types/alteration.js'; + +enum OldSignInIdentifier { + Email = 'email', + Sms = 'Sms', + Username = 'username', +} + +type OldSignIn = { + methods: Array<{ + password: boolean; + identifier: OldSignInIdentifier; + verificationCode: boolean; + isPasswordPrimary: boolean; + }>; +}; + +type OldSignUp = { + identifiers: OldSignInIdentifier[]; + password: boolean; + verify: boolean; +}; + +type OldSignInExperience = { + [k: string]: unknown; + id: string; + signIn: OldSignIn; + signUp: OldSignUp; +}; + +enum SignInIdentifier { + Email = 'email', + Phone = 'Phone', + Username = 'username', +} + +type SignIn = { + methods: Array<{ + password: boolean; + identifier: SignInIdentifier; + verificationCode: boolean; + isPasswordPrimary: boolean; + }>; +}; + +type SignUp = { + identifiers: SignInIdentifier[]; + password: boolean; + verify: boolean; +}; + +type SignInExperience = { + [k: string]: unknown; + id: string; + signIn: SignIn; + signUp: SignUp; +}; + +const alterSignUp = (signUp: OldSignUp) => { + const { identifiers, password, verify } = signUp; + + const newIdentifiers = identifiers.map((identifier) => { + if (identifier === OldSignInIdentifier.Sms) { + return SignInIdentifier.Phone; + } + + return identifier; + }); + + return { + identifiers: newIdentifiers, + password, + verify, + }; +}; + +const alterSignIn = (signIn: OldSignIn) => { + const { methods } = signIn; + + const newMethods = methods.map((method) => { + const { identifier, ...rest } = method; + + if (identifier === OldSignInIdentifier.Sms) { + return { + identifier: SignInIdentifier.Phone, + ...rest, + }; + } + + return method; + }); + + return { + methods: newMethods, + }; +}; + +const rollbackSignUp = (signUp: SignUp) => { + const { identifiers, password, verify } = signUp; + + const newIdentifiers = identifiers.map((identifier) => { + if (identifier === SignInIdentifier.Phone) { + return OldSignInIdentifier.Sms; + } + + return identifier; + }); + + return { + identifiers: newIdentifiers, + password, + verify, + }; +}; + +const rollbackSignIn = (signIn: SignIn) => { + const { methods } = signIn; + + const newMethods = methods.map((method) => { + const { identifier, ...rest } = method; + + if (identifier === SignInIdentifier.Phone) { + return { + identifier: OldSignInIdentifier.Sms, + ...rest, + }; + } + + return method; + }); + + return { + methods: newMethods, + }; +}; + +const alteration: AlterationScript = { + up: async (pool) => { + const id = 'default'; + const data = await pool.maybeOne( + sql`select * from sign_in_experiences where id = ${id}` + ); + + if (data) { + const { signUp, signIn } = data; + + const newSignUp = alterSignUp(signUp); + const newSignIn = alterSignIn(signIn); + + await pool.query( + sql`update sign_in_experiences set sign_up = ${JSON.stringify(newSignUp)} where id = ${id}` + ); + + await pool.query( + sql`update sign_in_experiences set sign_in = ${JSON.stringify(newSignIn)} where id = ${id}` + ); + } + }, + down: async (pool) => { + const id = 'default'; + const data = await pool.maybeOne( + sql`select * from sign_in_experiences where id = ${id}` + ); + + if (data) { + const { signUp, signIn } = data; + + const oldSignUp = rollbackSignUp(signUp); + const oldSignIn = rollbackSignIn(signIn); + + await pool.query( + sql`update sign_in_experiences set sign_up = ${JSON.stringify(oldSignUp)} where id = ${id}` + ); + + await pool.query( + sql`update sign_in_experiences set sign_in = ${JSON.stringify(oldSignIn)} where id = ${id}` + ); + } + }, +}; + +export default alteration; diff --git a/packages/schemas/src/foundations/jsonb-types.ts b/packages/schemas/src/foundations/jsonb-types.ts index 74bdfa447..7d43a75cf 100644 --- a/packages/schemas/src/foundations/jsonb-types.ts +++ b/packages/schemas/src/foundations/jsonb-types.ts @@ -127,7 +127,7 @@ export type LanguageInfo = z.infer; export enum SignInIdentifier { Username = 'username', Email = 'email', - Sms = 'sms', + Phone = 'phone', } export const signUpGuard = z.object({ diff --git a/packages/ui/src/App.tsx b/packages/ui/src/App.tsx index 5a5215e04..5323c882f 100644 --- a/packages/ui/src/App.tsx +++ b/packages/ui/src/App.tsx @@ -99,7 +99,7 @@ const App = () => { {/* Continue set up missing profile */} } /> } /> diff --git a/packages/ui/src/__mocks__/logto.tsx b/packages/ui/src/__mocks__/logto.tsx index fbae28a93..35b438c03 100644 --- a/packages/ui/src/__mocks__/logto.tsx +++ b/packages/ui/src/__mocks__/logto.tsx @@ -166,8 +166,8 @@ export const emailSignInMethod = { isPasswordPrimary: true, }; -export const smsSignInMethod = { - identifier: SignInIdentifier.Sms, +export const phoneSignInMethod = { + identifier: SignInIdentifier.Phone, password: true, verificationCode: true, isPasswordPrimary: true, @@ -203,7 +203,7 @@ export const mockSignInExperience: SignInExperience = { verify: true, }, signIn: { - methods: [usernameSignInMethod, emailSignInMethod, smsSignInMethod], + methods: [usernameSignInMethod, emailSignInMethod, phoneSignInMethod], }, socialSignInConnectorTargets: ['BE8QXN0VsrOH7xdWFDJZ9', 'lcXT4o2GSjbV9kg2shZC7'], signInMode: SignInMode.SignInAndRegister, @@ -225,6 +225,6 @@ export const mockSignInExperienceSettings: SignInExperienceResponse = { signInMode: SignInMode.SignInAndRegister, forgotPassword: { email: true, - sms: true, + phone: true, }, }; diff --git a/packages/ui/src/components/ForgotPasswordLink/index.tsx b/packages/ui/src/components/ForgotPasswordLink/index.tsx index 0b2a254c0..3c394763e 100644 --- a/packages/ui/src/components/ForgotPasswordLink/index.tsx +++ b/packages/ui/src/components/ForgotPasswordLink/index.tsx @@ -4,7 +4,7 @@ import TextLink from '@/components/TextLink'; import { UserFlow } from '@/types'; type Props = { - method: SignInIdentifier.Email | SignInIdentifier.Sms; + method: SignInIdentifier.Email | SignInIdentifier.Phone; className?: string; }; diff --git a/packages/ui/src/containers/EmailForm/EmailForm.tsx b/packages/ui/src/containers/EmailForm/EmailForm.tsx index 7414039b4..cf746c91b 100644 --- a/packages/ui/src/containers/EmailForm/EmailForm.tsx +++ b/packages/ui/src/containers/EmailForm/EmailForm.tsx @@ -87,7 +87,7 @@ const EmailForm = ({ }} /> {errorMessage && {errorMessage}} - {hasSwitch && } + {hasSwitch && } {hasTerms && }