diff --git a/packages/auth0-acul-js/interfaces/screens/email-identifier-challenge.ts b/packages/auth0-acul-js/interfaces/screens/email-identifier-challenge.ts index 75e39731e..c384054d6 100644 --- a/packages/auth0-acul-js/interfaces/screens/email-identifier-challenge.ts +++ b/packages/auth0-acul-js/interfaces/screens/email-identifier-challenge.ts @@ -23,4 +23,9 @@ export interface EmailIdentifierChallengeMembers extends BaseMembers { resendCode(payload?: CustomOptions): Promise; resendManager(payload?: StartResendOptions): ResendControl; returnToPrevious(payload?: CustomOptions): Promise; + /** + * Switches from OTP/code authentication to password authentication. + * When called, the screen will re-render to the password authentication screen. + */ + switchToPasswordAuth(): Promise; } diff --git a/packages/auth0-acul-js/interfaces/screens/login-password.ts b/packages/auth0-acul-js/interfaces/screens/login-password.ts index 120463d08..f4e5ada92 100644 --- a/packages/auth0-acul-js/interfaces/screens/login-password.ts +++ b/packages/auth0-acul-js/interfaces/screens/login-password.ts @@ -61,4 +61,9 @@ export interface LoginPasswordMembers extends BaseMembers { login(payload: LoginPasswordOptions): Promise; federatedLogin(payload: FederatedLoginOptions): Promise; switchConnection(payload: SwitchConnectionOptions): Promise; + /** + * Switches from password authentication to OTP authentication. + * When called, the screen will re-render to the OTP authentication screen. + */ + switchToOtpAuth(): Promise; } diff --git a/packages/auth0-acul-js/interfaces/screens/phone-identifier-challenge.ts b/packages/auth0-acul-js/interfaces/screens/phone-identifier-challenge.ts index 699bbf465..7093ec576 100644 --- a/packages/auth0-acul-js/interfaces/screens/phone-identifier-challenge.ts +++ b/packages/auth0-acul-js/interfaces/screens/phone-identifier-challenge.ts @@ -41,4 +41,9 @@ export interface PhoneIdentifierChallengeMembers extends BaseMembers { returnToPrevious(payload?: CustomOptions): Promise; switchToVoice(payload?: CustomOptions): Promise; switchToText(payload?: CustomOptions): Promise; + /** + * Switches from OTP/code authentication to password authentication. + * When called, the screen will re-render to the password authentication screen. + */ + switchToPasswordAuth(): Promise; } diff --git a/packages/auth0-acul-js/src/constants/form-actions.ts b/packages/auth0-acul-js/src/constants/form-actions.ts index 7995cb4c8..a75671e43 100644 --- a/packages/auth0-acul-js/src/constants/form-actions.ts +++ b/packages/auth0-acul-js/src/constants/form-actions.ts @@ -30,4 +30,8 @@ export const FormActions = { TRY_AGAIN: 'tryagain' as const, USE_PASSWORD: 'use-password' as const, CHANGE_LANGUAGE: 'change-language' as const, + // actions for login-password screen + SWITCH_TO_OTP_AUTH: 'switch-to-otp-auth' as const, + // actions for email-identifier-challenge screen + SWITCH_TO_PASSWORD_AUTH: 'switch-to-password-auth' as const, } as const; diff --git a/packages/auth0-acul-js/src/screens/email-identifier-challenge/index.ts b/packages/auth0-acul-js/src/screens/email-identifier-challenge/index.ts index a0eb823f7..01ed90b2d 100644 --- a/packages/auth0-acul-js/src/screens/email-identifier-challenge/index.ts +++ b/packages/auth0-acul-js/src/screens/email-identifier-challenge/index.ts @@ -109,6 +109,31 @@ export default class EmailIdentifierChallenge extends BaseContext implements Ema !!this.screen.data?.resendLimitReached ); } + + /** + * @remarks + * This method switches from OTP/code authentication to password authentication. + * When called, the screen will re-render to the password authentication screen. + * + * @example + * import EmailIdentifierChallenge from '@auth0/auth0-acul-js/email-identifier-challenge'; + * + * const emailIdentifierChallenge = new EmailIdentifierChallenge(); + * + * // Switch to password authentication + * emailIdentifierChallenge.switchToPasswordAuth(); + */ + async switchToPasswordAuth(): Promise { + const options: FormOptions = { + state: this.transaction.state, + telemetry: [EmailIdentifierChallenge.screenIdentifier, 'switchToPasswordAuth'], + }; + + await new FormHandler(options).submitData({ + code: '', + action: FormActions.SWITCH_TO_PASSWORD_AUTH, + }); + } } export { EmailIdentifierChallengeMembers, ScreenOptions as ScreenMembersOnEmailIdentifierChallenge, EmailChallengeOptions }; diff --git a/packages/auth0-acul-js/src/screens/login-password/index.ts b/packages/auth0-acul-js/src/screens/login-password/index.ts index 4fd1f838b..789f0bebe 100644 --- a/packages/auth0-acul-js/src/screens/login-password/index.ts +++ b/packages/auth0-acul-js/src/screens/login-password/index.ts @@ -1,4 +1,4 @@ -import { ScreenIds } from '../../constants'; +import { ScreenIds, FormActions } from '../../constants'; import { BaseContext } from '../../models/base-context'; import { getBrowserCapabilities } from '../../utils/browser-capabilities'; import { FormHandler } from '../../utils/form-handler'; @@ -110,6 +110,30 @@ export default class LoginPassword extends BaseContext implements LoginPasswordM await new FormHandler(options).submitData(payload); } + + /** + * @remarks + * This method switches from password authentication to OTP authentication. + * When called, the screen will re-render to the OTP authentication screen. + * + * @example + * import LoginPassword from "@auth0/auth0-acul-js/login-password"; + * + * const loginPasswordManager = new LoginPassword(); + * + * // Switch to OTP authentication + * loginPasswordManager.switchToOtpAuth(); + */ + async switchToOtpAuth(): Promise { + const options: FormOptions = { + state: this.transaction.state, + telemetry: [LoginPassword.screenIdentifier, 'switchToOtpAuth'], + }; + + await new FormHandler(options).submitData({ + action: FormActions.SWITCH_TO_OTP_AUTH, + }); + } } export { diff --git a/packages/auth0-acul-js/src/screens/phone-identifier-challenge/index.ts b/packages/auth0-acul-js/src/screens/phone-identifier-challenge/index.ts index 3eb46188f..ccc200e8b 100644 --- a/packages/auth0-acul-js/src/screens/phone-identifier-challenge/index.ts +++ b/packages/auth0-acul-js/src/screens/phone-identifier-challenge/index.ts @@ -141,6 +141,31 @@ export default class PhoneIdentifierChallenge extends BaseContext implements Pho !!this.screen.data?.resendLimitReached ); } + + /** + * @remarks + * This method switches from OTP/code authentication to password authentication. + * When called, the screen will re-render to the password authentication screen. + * + * @example + * import PhoneIdentifierChallenge from '@auth0/auth0-acul-js/phone-identifier-challenge'; + * + * const phoneIdentifierChallenge = new PhoneIdentifierChallenge(); + * + * // Switch to password authentication + * phoneIdentifierChallenge.switchToPasswordAuth(); + */ + async switchToPasswordAuth(): Promise { + const options: FormOptions = { + state: this.transaction.state, + telemetry: [PhoneIdentifierChallenge.screenIdentifier, 'switchToPasswordAuth'], + }; + + await new FormHandler(options).submitData({ + code: '', + action: FormActions.SWITCH_TO_PASSWORD_AUTH, + }); + } } export { PhoneIdentifierChallengeMembers, PhoneChallengeOptions, ScreenOptions as ScreenMembersOnPhoneIdentifierChallenge };