@@ -29,6 +29,7 @@ import {
2929import LoginForm from '@salesforce/retail-react-app/app/components/login'
3030import ResetPasswordForm from '@salesforce/retail-react-app/app/components/reset-password'
3131import RegisterForm from '@salesforce/retail-react-app/app/components/register'
32+ import PasswordlessEmailConfirmation from '@salesforce/retail-react-app/app/components/email-confirmation/index'
3233import OtpAuth from '@salesforce/retail-react-app/app/components/otp-auth'
3334import { noop } from '@salesforce/retail-react-app/app/utils/utils'
3435import { API_ERROR_MESSAGE } from '@salesforce/retail-react-app/app/constants'
@@ -110,14 +111,11 @@ export const AuthModal = ({
110111 locale : locale . id ,
111112 ...( callbackURL && { callbackURI : `${ callbackURL } ?redirectUrl=${ redirectPath } ` } )
112113 } )
113- // Close AuthModal first, then open OtpAuth modal after a brief delay
114- onClose ( )
115- setTimeout ( ( ) => {
116- setIsOtpAuthOpen ( true )
117- } , 150 ) // Small delay to allow AuthModal to close first
114+ return { success : true }
118115 } catch ( error ) {
119116 const message = formatMessage ( getAuthorizePasswordlessErrorMessage ( error . message ) )
120117 form . setError ( 'global' , { type : 'manual' , message} )
118+ return { success : false }
121119 }
122120 }
123121
@@ -160,7 +158,15 @@ export const AuthModal = ({
160158 login : async ( data ) => {
161159 if ( isPasswordless ) {
162160 const email = data . email
163- await handlePasswordlessLogin ( email )
161+ const { success} = await handlePasswordlessLogin ( email )
162+ // Only close AuthModal and open OtpAuth modal if passwordless login succeeded
163+ if ( success ) {
164+ // Close AuthModal first, then open OtpAuth modal after a brief delay
165+ onClose ( )
166+ setTimeout ( ( ) => {
167+ setIsOtpAuthOpen ( true )
168+ } , 150 ) // Small delay to allow AuthModal to close first
169+ }
164170 return
165171 }
166172
@@ -204,6 +210,10 @@ export const AuthModal = ({
204210 const message = formatMessage ( getPasswordResetErrorMessage ( e . message ) )
205211 form . setError ( 'global' , { type : 'manual' , message} )
206212 }
213+ } ,
214+ email : async ( ) => {
215+ const email = form . getValues ( ) . email || initialEmail
216+ await handlePasswordlessLogin ( email )
207217 }
208218 } [ currentView ] ( data )
209219 }
@@ -346,6 +356,13 @@ export const AuthModal = ({
346356 clickSignIn = { onBackToSignInClick }
347357 />
348358 ) }
359+ { currentView === EMAIL_VIEW && (
360+ < PasswordlessEmailConfirmation
361+ form = { form }
362+ submitForm = { submitForm }
363+ email = { form . getValues ( ) . email || initialEmail }
364+ />
365+ ) }
349366 </ ModalBody >
350367 </ ModalContent >
351368 </ Modal >
0 commit comments