Skip to content

Commit bba25a2

Browse files
committed
Revert "test commit (revert use-auth-modal to develop)"
This reverts commit faa5454.
1 parent faa5454 commit bba25a2

File tree

2 files changed

+428
-12
lines changed

2 files changed

+428
-12
lines changed

packages/template-retail-react-app/app/hooks/use-auth-modal.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import {usePrevious} from '@salesforce/retail-react-app/app/hooks/use-previous'
4343
import {usePasswordReset} from '@salesforce/retail-react-app/app/hooks/use-password-reset'
4444
import {isServer} from '@salesforce/retail-react-app/app/utils/utils'
4545
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
46+
import {usePasskeyRegistration} from '@salesforce/retail-react-app/app/hooks/use-passkey-registration'
47+
import {usePasskeyLogin} from '@salesforce/retail-react-app/app/hooks/use-passkey-login'
4648
import {getPasswordlessCallbackUrl} from '@salesforce/retail-react-app/app/utils/auth-utils'
4749
import useMultiSite from '@salesforce/retail-react-app/app/hooks/use-multi-site'
4850

@@ -73,7 +75,7 @@ export const AuthModal = ({
7375
const customerId = useCustomerId()
7476
const {isRegistered, customerType} = useCustomerType()
7577
const prevAuthType = usePrevious(customerType)
76-
78+
const {loginWithPasskey} = usePasskeyLogin()
7779
const customer = useCustomer(
7880
{parameters: {customerId}},
7981
{enabled: !!customerId && isRegistered}
@@ -101,6 +103,8 @@ export const AuthModal = ({
101103
)
102104
const mergeBasket = useShopperBasketsMutation('mergeBasket')
103105

106+
const {showRegisterPasskeyToast} = usePasskeyRegistration()
107+
104108
const handlePasswordlessLogin = async (email) => {
105109
try {
106110
const redirectPath = window.location.pathname + (window.location.search || '')
@@ -233,6 +237,10 @@ export const AuthModal = ({
233237
if (isOpen) {
234238
setCurrentView(initialView)
235239
form.reset()
240+
// Prompt user to login without username (discoverable credentials)
241+
loginWithPasskey().catch(() => {
242+
form.setError('global', {type: 'manual', message: formatMessage(API_ERROR_MESSAGE)})
243+
})
236244
}
237245
}, [isOpen])
238246

@@ -270,8 +278,12 @@ export const AuthModal = ({
270278
onClose()
271279
setIsOtpAuthOpen(false)
272280

281+
// Show passkey registration prompt if supported
282+
showRegisterPasskeyToast()
283+
273284
// Show a toast only for those registed users returning to the site.
274-
if (loggingIn) {
285+
// Only show toast when customer data is available (user is logged in and data is loaded)
286+
if (loggingIn && customer.data) {
275287
toast({
276288
variant: 'subtle',
277289
title: `${formatMessage(
@@ -301,7 +313,7 @@ export const AuthModal = ({
301313
// Execute action to be performed on successful registration
302314
onRegistrationSuccess()
303315
}
304-
}, [isRegistered])
316+
}, [isRegistered, customer.data])
305317

306318
const onBackToSignInClick = () =>
307319
initialView === PASSWORD_VIEW ? onClose() : setCurrentView(LOGIN_VIEW)

0 commit comments

Comments
 (0)