@salesforce/retail-react-app 10.4.0-nightly-20261106080302 → 11.0.0-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -7
- package/app/components/drawer-menu/drawer-menu.jsx +2 -0
- package/app/components/drawer-menu/drawer-menu.test.js +4 -0
- package/app/components/header/index.jsx +2 -0
- package/app/hooks/use-auth-modal.js +35 -7
- package/app/hooks/use-password-reset.js +8 -1
- package/app/hooks/use-password-reset.test.js +45 -0
- package/app/pages/account/index.jsx +2 -0
- package/app/pages/checkout/partials/contact-info.jsx +2 -0
- package/app/pages/checkout-one-click/partials/one-click-contact-info.jsx +35 -14
- package/app/pages/checkout-one-click/partials/one-click-user-registration.jsx +44 -10
- package/app/pages/checkout-one-click/partials/one-click-user-registration.test.js +3 -1
- package/app/pages/login/index.jsx +86 -11
- package/app/pages/login/passwordless-landing.test.js +159 -9
- package/app/pages/reset-password/index.test.jsx +33 -0
- package/app/pages/reset-password/reset-password-landing.jsx +22 -10
- package/app/routes.jsx +12 -5
- package/app/routes.test.js +33 -1
- package/app/ssr.js +3 -0
- package/app/ssr.test.js +25 -0
- package/app/static/translations/compiled/en-GB.json +12 -0
- package/app/static/translations/compiled/en-US.json +12 -0
- package/app/static/translations/compiled/en-XA.json +28 -0
- package/app/utils/auth-utils.js +140 -1
- package/app/utils/auth-utils.test.js +159 -0
- package/package.json +7 -7
- package/translations/en-GB.json +6 -0
- package/translations/en-US.json +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
##
|
|
1
|
+
## v11.0.0-preview.0 (Nov 09, 2026)
|
|
2
|
+
- [Feature] Export `getDynamicRoutes(config)` from `app/routes` so projects that extend this template can include the config-gated routes (reset password and passwordless login landing pages, social login redirect, guest order lookup, Shopper Agent express payment).
|
|
3
|
+
- [Security] Require `login_id` and `channel_id` on passwordless OTP token exchange (`loginPasswordless`) from the login page, auth modal, and one-click checkout contact/registration flows, so SLAS can reject mismatched identifiers. Map SLAS 400 missing/mismatched-identifier errors and passwordless rate limits (429) to existing OTP/login UX, and map password/action rate limits (429) to the too-many-password-reset-attempts UX. Depends on `@salesforce/commerce-sdk-react@6.0.0` (breaking major; pairs with `commerce-sdk-isomorphic@5.8.0`). [#4075](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4075)
|
|
4
|
+
- [Security] Passwordless magic links no longer carry the shopper email. When the shopper opens the link in the browser that requested it, the login landing page sends the email remembered at request time (stored in `localStorage` for 15 minutes) as `login_id`; in any other browser or device it keeps the token and asks the shopper to confirm their email to finish signing in. A `login_id` query parameter (for example in a merchant-configured `email` mode link) is still accepted. Token exchange failures on the landing page are now shown instead of leaving the shopper on the sign-in page with no feedback. **Upgrade note:** if your project overrides the login page, auth modal, or one-click checkout contact/registration components, call `rememberPasswordlessLoginId(email)` after each successful `authorizePasswordless` call so same-browser magic links sign in without the extra step. Both remembered emails are cleared on logout; if you add your own logout action, call `clearRememberedAuthEmails()` there too. [#4092](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4092)
|
|
5
|
+
- [Feature] The reset password landing page prefills the email when the shopper opens the link in the browser that requested it (stored in `localStorage` for 15 minutes, separately from the passwordless email, and cleared after a successful reset). In any other browser the shopper enters it as before. The reset link still carries only the token. [#4092](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4092)
|
|
2
6
|
- [Enhancement] Update guest order lookup copy per the UI text review: the request page now reads "Order Lookup" with revised intro text, title-case field labels, and a "Find Order" button; the verify page uses "Enter the verification code that we sent to {email}.". Remove the placeholder "Order Status" footer link, which pointed to the home page. [#4090](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4090)
|
|
3
7
|
- [Bugfix] Keep Commerce Client shopper-agent product links on the PWA Kit storefront. The agent backend sends product links as SFRA URLs on the backend origin (e.g. `/en_US/<slug>-<id>.html`), which the widget's `onNavigate` never sees, so clicking a product card left for the SFRA PDP. The storefront now reads the product id from those links in the widget's product slots (cards, product detail title, comparison columns), rewrites their `href` to the PWA product page, and routes plain clicks through the router. Links in agent message text are left alone. When the product id is not certain from the URL (the last path segment contains `-`, so it may be a name slug and id, or an id that contains `-`), it is resolved through Shopper SEO `getUrlMapping`; if that finds no product the link keeps its backend URL rather than pointing at a storefront 404. [#4076](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4076)
|
|
4
8
|
- [Feature] Add a neutral Shopper Agent express-payment iframe framework with cart and product routes, a merchant provider lifecycle contract, validated iframe-to-host events, and automatic iframe sizing. [#4063](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4063)
|
|
@@ -7,17 +11,22 @@
|
|
|
7
11
|
- [Bugfix] Gate the GLO magic-link auto-submit on `emailFromContext` (email present in router state) rather than the derived `email` variable, so arriving directly via magic link no longer attempts an auto-submit before the user enters their email address. [#4067](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4067)
|
|
8
12
|
- [Enhancement] Update inline agent widget UMD bundle: add follow-up suggestion pills from agent responses, and send `commerce_agent_context` as a TextValue JSON string. Bump the embedded agent `capabilitiesVersion` to `66` (new `DEFAULT_EMBEDDED_AGENT_CAPABILITIES_VERSION` constant, separate from the Commerce Client's `65`) for context-variable support. Built from [inline-agent-widget#17](https://github.com/SalesforceCommerceCloud/inline-agent-widget/pull/17) and [inline-agent-widget#18](https://github.com/SalesforceCommerceCloud/inline-agent-widget/pull/18). [#4061](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4061)
|
|
9
13
|
- [Bugfix] Temporarily pin transitive Vitest to 4.1.11 to avoid an npm 10 dependency resolver crash during fresh installs while the Vitest browser packages require 4.1.11.
|
|
10
|
-
- [Bugfix] Fix `useScript` remount when the script tag is already in the DOM. ShopperAgent (and other consumers) stayed at `loaded: false` after a remount because the existing tag never fired `load` again, so the Commerce Client widget did not re-inject. The hook now stamps `data-script-status` on load/error and only reports `loaded: true` when that status is `ready`; an in-flight tag stays unloaded until it finishes. [#4062](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4062)
|
|
14
|
+
- [Bugfix] Fix `useScript` remount when the script tag is already in the DOM. ShopperAgent (and other consumers) stayed at `loaded: false` after a remount because the existing tag never fired `load` again, so the Commerce Client widget did not re-inject. The hook now stamps `data-script-status` on load/error and only reports `loaded: true` when that status is `ready`; an in-flight tag stays unloaded until it finishes. [#4062](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4062)
|
|
11
15
|
- [Bugfix] Route Commerce Client widget product/checkout/markdown clicks through the storefront `useNavigation` router via the widget's `onNavigate` callback, so same-tab same-origin links stay in the SPA instead of triggering a full page load. Requires Commerce Client widget `1.48.0+`. `cc_openLinksInNewTab: "true"` is unchanged and still opens a new tab. Also fixes `buildUrl` (`createUrlTemplate`) when site/locale are configured as `query_param`: paths that already have a query string or hash now get site/locale merged into the existing query instead of a second `?` appended (which previously corrupted params like `q`/`pid` and swallowed the hash).
|
|
12
16
|
- [Enhancement] Update inline agent widget UMD bundle: replace the text-prefix product-context hack with the proper SCRT2 v2 session-context API. Product context is now sent as a `commerce_agent_context` StructuredValue in the SessionContextSet envelope, leaving the shopper's message text unchanged. Default `capabilitiesVersion` bumped to `"65"`. Built from [inline-agent-widget#3](https://github.com/SalesforceCommerceCloud/inline-agent-widget/pull/3). [#4054](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4054)
|
|
13
17
|
- [Feature] Add `app_pwakit_base` B2C cartridge for transactional email delivery via ISML templates and `dw/net/Mail`. GLO access-code emails use the `sfcc.app.order.sendOrderAccessCode` hook; passwordless login, OTP verification, and password reset use the `pwakit-notify` Custom REST API (`POST .../organizations/{orgId}/notify?siteId={siteId}`, guarded by the `c_pwakit_notify` SLAS scope). Deploy with `npm run deploy:cartridge` from `packages/template-retail-react-app` (uses `b2c-cli` with `--reload` to upload the cartridge and re-register the SCAPI endpoint in one step), then import `OrganizationPreferences.xml` to enable the `pwakitNotifyEnabled` and `pwakitStorefrontHost` site preferences. **Required: create a dedicated private SLAS client** (`notifyClientId`) scoped only to `c_pwakit_notify`, set `PWA_KIT_NOTIFY_SLAS_CLIENT_SECRET` to its secret, and add `notifyClientId` to `commerceAPI.parameters` in your config. **Do not add `c_pwakit_notify` to the shopper/public client** — doing so makes browser-minted guest tokens capable of calling the notification API directly, reopening the email-relay risk this design is intended to close. See `cartridges/app_pwakit_base/README.md` for full setup steps. [#4012](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4012)
|
|
14
18
|
- [Breaking change] `config/default.js` now sets `mode: 'callback'` for both `passwordless` and `resetPassword` flows (previously `'email'`). This routes password-reset confirmation through the SSR `/reset-password-callback` route and the new `pwakit-notify` cartridge. **Projects that adopt this config without deploying the cartridge will have broken password resets** — there is no `resetPassword.enabled` guard (unlike `passwordless.enabled`). Either deploy the cartridge before adopting the config change, or explicitly override `resetPassword.mode` back to `'email'`. [#4012](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4012)
|
|
19
|
+
- [Breaking change] Marketing Cloud email delivery is removed from `app/ssr.js`. The `emailLink` function and the `MARKETING_CLOUD_CLIENT_ID`, `MARKETING_CLOUD_CLIENT_SECRET`, `MARKETING_CLOUD_SUBDOMAIN`, `MARKETING_CLOUD_PASSWORDLESS_LOGIN_TEMPLATE` and `MARKETING_CLOUD_RESET_PASSWORD_TEMPLATE` environment variables are no longer read. Passwordless login, password reset and registration emails are now sent through the `pwakit-notify` endpoint of the `app_pwakit_base` cartridge. Projects that send these emails through Marketing Cloud must deploy the cartridge and configure `notifyClientId` and `PWA_KIT_NOTIFY_SLAS_CLIENT_SECRET`, or keep their own copy of the previous `emailLink` implementation in an overridden `ssr.js`. [#4012](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4012)
|
|
20
|
+
- [Breaking change] `config/default.js` now sets `passwordless.enabled` to `true` (previously `false`). Combined with `mode: 'callback'`, projects that inherit this config need the `app_pwakit_base` cartridge deployed or must set `passwordless.enabled` back to `false`. [#4012](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4012)
|
|
21
|
+
- [Breaking change] `config/default.js` now sets `guestOrderLookup.enabled` to `true` (previously `false`). This enables the `/order-lookup` routes and the order access code email, which is sent by the cartridge's `sendOrderAccessCode` hook. Deploy the `app_pwakit_base` cartridge or set `guestOrderLookup.enabled` back to `false`. [#4012](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4012)
|
|
22
|
+
- [Breaking change] Projects that override passwordless or reset password code must update their calls: `loginPasswordless` now needs `login_id` (the email sent to `authorizePasswordless`) and `channel_id` (the site id), and `resetPassword` now needs `user_id` (the email the reset was requested for). See the `@salesforce/commerce-sdk-react` 6.0.0 changelog. [#4075](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4075), [#4092](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4092)
|
|
15
23
|
- [Bugfix] Fix GLO `/api/guestOrderLookup/verify` and related server endpoints returning 401 when `enablePWAKitPrivateClient` is enabled. The `cc-nx-g_` cookie stores the SLAS refresh token, not the access token — the access token is never stored in any cookie. All GLO server endpoints now read the SLAS JWT from the `Authorization` header sent by the client (via `useAccessToken().getTokenWhenReady()`), which works correctly in both public and private client modes. [#4012](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4012)
|
|
16
|
-
- [Enhancement] End the Commerce Client shopper-agent conversation when a registered shopper logs out, instead of re-linking it to the guest. Uses the widget's `eventHandlers.session.endConversation()` (`cc_cdnVersion` >= `1.39.0`), falls back to `resetConversation()` on `1.36.0`–`1.38.x`, and to re-linking before `1.36.0`. Also keeps the widget mounted through the login/logout basket reload so the bundle is not injected twice. [#4051](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4051)
|
|
24
|
+
- [Enhancement] End the Commerce Client shopper-agent conversation when a registered shopper logs out, instead of re-linking it to the guest. Uses the widget's `eventHandlers.session.endConversation()` (`cc_cdnVersion` >= `1.39.0`), falls back to `resetConversation()` on `1.36.0`–`1.38.x`, and to re-linking before `1.36.0`. Also keeps the widget mounted through the login/logout basket reload so the bundle is not injected twice. [#4051](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4051)
|
|
25
|
+
- [Enhancement] Commerce Client shopper identity linking now retrieves the auth link key via the widget's `window.CimulateMessaging.getAuthLinkKey()` when the bundle exposes it, instead of calling SCRT2's `/iamessage/api/v2/authorization/authlink` endpoint directly with the Commerce Client JWT. Older bundles without the function fall back to the direct SCRT2 call (feature-detected, not version-checked). A `getAuthLinkKey()` rejection is surfaced as a linking failure rather than retried via the fallback, since both paths hit the same endpoint. [#4050](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4050)
|
|
26
|
+
- [Feature] Add embedded Page Designer content-block support to the retail template, including an Announcement Banner content component, a preview-only Header layout, and a chrome-free `/preview/component` route for standalone component previews. [#4042](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4042)
|
|
27
|
+
- [Feature] Add opener question pills to the inline agent widget on the PDP. The Product Detail page parses SCAPI `c_pdpQuestions` (a JSON-encoded array of strings published by Commerce Content Studio) and forwards it to the widget via the new `pdp-questions` attribute. The widget renders up to 5 tappable pills above the input; tapping a pill sends it through the same message path as typed input, and pills auto-hide once the shopper engages. On SPA navigation between PDPs the pills re-appear for the new product's list. Malformed or absent `c_pdpQuestions` renders no pills.
|
|
17
28
|
|
|
18
29
|
## v10.3.0 (Oct 08, 2026)
|
|
19
|
-
- [Enhancement] Commerce Client shopper identity linking now retrieves the auth link key via the widget's `window.CimulateMessaging.getAuthLinkKey()` when the bundle exposes it, instead of calling SCRT2's `/iamessage/api/v2/authorization/authlink` endpoint directly with the Commerce Client JWT. Older bundles without the function fall back to the direct SCRT2 call (feature-detected, not version-checked). A `getAuthLinkKey()` rejection is surfaced as a linking failure rather than retried via the fallback, since both paths hit the same endpoint. [#4050](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4050) (W-24076703)
|
|
20
|
-
- [Feature] Add embedded Page Designer content-block support to the retail template, including an Announcement Banner content component, a preview-only Header layout, and a chrome-free `/preview/component` route for standalone component previews. [#4042](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4042)
|
|
21
30
|
- [Enhancement] Rename `INLINE_AGENT_WIDGET_COMMERCE_SETTINGS` environment variable to `EMBEDDED_AGENT_COMMERCE_SETTINGS` and config key `inlineAgentWidget` to `embeddedAgent` to align with updated product terminology. [#4041](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4041)
|
|
22
31
|
- [Feature] Add a configurable `cc_enableImageUpload` toggle for the Commerce Client (Embedded Messaging) shopper-agent widget, defaulting to `'false'` and forwarded to the bundle as `messagingConfig.enableImageUpload`. Set it to `'true'` via `COMMERCE_AGENT_SETTINGS` to let shoppers upload images in the chat; requires a Commerce Client bundle that supports image upload (`cc_cdnVersion` >= `1.44.0`) plus the backend file-upload prerequisites. Also adds `blob:` and `data:` to the `img-src` CSP directive in `app/ssr.js` so the widget can render the pre-send preview (a `blob:` URL) and the sent-image thumbnail (a `data:` URL); the widget renders images locally only, so no image host is added. [#4030](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4030)
|
|
23
32
|
- [Feature] Add the `dw_attribution` first-touch marketing-attribution cookie (W-23493129). The app writes a sanitized, allowlist-only campaign cookie client-side on load so Salesforce CIP can attribute placed orders back to the campaign that drove a headless-storefront visit. Writing in the browser (not on SSR) means it also fires on a CDN document-cache hit — where the SSR handler never runs — and lets the app clear the cookie the instant a shopper opts out; campaign landing pages stay fully cacheable. The Secure + `SameSite=Lax` cookie has a 30-minute write-once TTL and stores percent-encoded `key=value` pairs (`utm_source`/`utm_medium`/`utm_campaign`/`utm_term`/`utm_content`, `gclid`, `fbclid`, `msclkid`, and a sanitized external `ref` — origin, path, and its own allowlisted params only); no free-text query params are captured. It is write-once (first touch wins) and honors Do Not Track (`dw_dnt=1`): while opted out it captures nothing and expires any existing cookie.
|
|
@@ -32,8 +41,7 @@
|
|
|
32
41
|
- [Enhancement] Update inline agent widget UMD bundle: auto-restart session on expiry instead of showing an error. The widget silently resets to idle and the next message starts a fresh session transparently. [#4015](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4015)
|
|
33
42
|
- [Enhancement] Update inline agent widget UMD bundle: show user question bubble, add 4,000-character message limit, improve error handling with generic user-facing messages, fix 403 stale-conversation reset, and hide restored session Q&A on page reload. [#4032](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4032)
|
|
34
43
|
- [Enhancement] Update inline agent widget UMD bundle: suppress agent welcome message on conversation start, and clear stale question/answer when navigating between product pages via SPA routing.
|
|
35
|
-
- [Feature] Add
|
|
36
|
-
- [Feature] Add Guest Order Lookup (GLO): unauthenticated shoppers can look up an order by order number and email, verify ownership via a time-limited 6-digit access code (valid for 15 minutes, reusable within the window), and view a filtered order detail page (shipment tracking, items, payment summary, shipping address). Server-side endpoints (`/api/guestOrderLookup/{verify,order,oms-meta,cancel,return}`) receive the SLAS access token via the `Authorization` header (sent by the client using `useAccessToken().getTokenWhenReady()`), call SCAPI with the shopper's bearer token, and filter the response to safe fields. The verify endpoint writes a `cc-goa_` HttpOnly cookie binding the order number to the verified access code; all subsequent order endpoints validate this cookie before proxying. [#3982](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3982)
|
|
44
|
+
- [Feature] Add Guest Order Lookup (GLO): unauthenticated shoppers can look up an order by order number and email, verify ownership via a time-limited 6-digit access code (valid for 15 minutes, reusable within the window), and view a filtered order detail page (shipment tracking, items, payment summary, shipping address). Server-side endpoints (`/api/guestOrderLookup/{verify,order,oms-meta,cancel,return}`) read the SLAS access token from the HttpOnly `cc-at_*` cookie, call SCAPI with the shopper's bearer token, and filter the response to safe fields. The verify endpoint writes a `cc-goa_` HttpOnly cookie binding the order number to the verified access code; all subsequent order endpoints validate this cookie before proxying. [#3982](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3982)
|
|
37
45
|
- [Feature] Forward two backend-gating signals on the Commerce Client shopper-agent widget's `routingAttributes`: `clientVersion` (sourced from `cc_cdnVersion`, so the runtime can gate rich components on the client's capability version; omitted when unset) and `isCartMgmtSupported` (string `'true'`/`'false'`, default `'false'`, read from `cc_routingAttributes`). Brings the PWA commerce-client path to parity with the SFRA cartridge.
|
|
38
46
|
- [Feature] Enable shopper identity (customer context) for the Commerce Client (Cimulate) shopper-agent provider. Unlike MIAW, Commerce Client widgets do not expose `getAuthLinkKey`, so the browser extracts the Commerce Client JWT from the deployment-scoped `cim_af_ct_<orgId>_<embeddedServiceName>` key (`sessionStorage` is authoritative; `localStorage` is a compatibility fallback) and calls SCRT2's `/iamessage/api/v2/authorization/authlink` endpoint directly (`auth-link-client.js`) with an `Authorization: Bearer <jwt>` header to obtain an `auth_link_key`. The SCRT2 origin comes from `scrt2Url` in `COMMERCE_AGENT_SETTINGS` (a different host from Core's My Domain) and is strictly validated before the token is sent (HTTPS only; no credentials, port, path, query, or fragment) against the Salesforce SCRT2 domain allowlist, with the request hardened (`credentials: 'omit'`, `redirect: 'error'`, `referrerPolicy: 'no-referrer'`, `cache: 'no-store'`) and bounded by a 10s abort timeout. The `auth_link_key` is then forwarded to the existing Token Bridge to bind the conversation to the shopper's SLAS session. Linking is idempotent — deduped by `conversationId` + SLAS identity — and re-runs both on a new conversation (`onCimulateWidgetReady`) and on a SLAS identity transition (guest ↔ registered / account switch), gated on `my_domain` resolution. [#3943](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3943) [#3981](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3981)
|
|
39
47
|
- [Bugfix] Restore Commerce Client shopper identity linking with widget 1.34.0+: read persisted conversation IDs from `localStorage` with a legacy `sessionStorage` fallback, and continue checking the other store when one contains the previously linked JWT so a stale session token cannot hide a newer local token. [#4033](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/4033) (W-24293344)
|
|
@@ -62,6 +62,7 @@ import useMultiSite from '@salesforce/retail-react-app/app/hooks/use-multi-site'
|
|
|
62
62
|
|
|
63
63
|
import {STORE_LOCATOR_IS_ENABLED} from '@salesforce/retail-react-app/app/constants'
|
|
64
64
|
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
|
|
65
|
+
import {clearRememberedAuthEmails} from '@salesforce/retail-react-app/app/utils/auth-utils'
|
|
65
66
|
// The FONT_SIZES and FONT_WEIGHTS constants are used to control the styling for
|
|
66
67
|
// the accordion buttons as their current depth. In the below definition we assign
|
|
67
68
|
// values for depths 0 - 3, any depth deeper than that will use the default styling.
|
|
@@ -108,6 +109,7 @@ const DrawerMenu = ({
|
|
|
108
109
|
const logout = useAuthHelper(AuthHelpers.Logout)
|
|
109
110
|
const onSignoutClick = async () => {
|
|
110
111
|
setShowLoading(true)
|
|
112
|
+
clearRememberedAuthEmails()
|
|
111
113
|
await logout.mutateAsync()
|
|
112
114
|
navigate('/login')
|
|
113
115
|
setShowLoading(false)
|
|
@@ -142,6 +142,8 @@ describe('DrawerMenu', () => {
|
|
|
142
142
|
|
|
143
143
|
test('handles logout action for registered users', async () => {
|
|
144
144
|
useCustomerType.mockReturnValue({isRegistered: true})
|
|
145
|
+
window.localStorage.setItem('pwdless_login_id', 'stored')
|
|
146
|
+
window.localStorage.setItem('pwd_reset_email', 'stored')
|
|
145
147
|
|
|
146
148
|
const {user} = renderWithProviders(<DrawerMenu isOpen={true} root={mockCategories.root} />)
|
|
147
149
|
|
|
@@ -154,6 +156,8 @@ describe('DrawerMenu', () => {
|
|
|
154
156
|
await user.click(logoutButton)
|
|
155
157
|
|
|
156
158
|
expect(mockLogout.mutateAsync).toHaveBeenCalledTimes(1)
|
|
159
|
+
expect(window.localStorage.getItem('pwdless_login_id')).toBeNull()
|
|
160
|
+
expect(window.localStorage.getItem('pwd_reset_email')).toBeNull()
|
|
157
161
|
await waitFor(() => {
|
|
158
162
|
expect(mockNavigate).toHaveBeenCalledWith('/login')
|
|
159
163
|
})
|
|
@@ -54,6 +54,7 @@ import {HideOnDesktop, HideOnMobile} from '@salesforce/retail-react-app/app/comp
|
|
|
54
54
|
import {isHydrated, noop} from '@salesforce/retail-react-app/app/utils/utils'
|
|
55
55
|
import {STORE_LOCATOR_IS_ENABLED} from '@salesforce/retail-react-app/app/constants'
|
|
56
56
|
import {getCommerceAgentConfig} from '@salesforce/retail-react-app/app/utils/config-utils'
|
|
57
|
+
import {clearRememberedAuthEmails} from '@salesforce/retail-react-app/app/utils/auth-utils'
|
|
57
58
|
const IconButtonWithRegistration = withRegistration(IconButton)
|
|
58
59
|
|
|
59
60
|
/**
|
|
@@ -150,6 +151,7 @@ const Header = ({
|
|
|
150
151
|
|
|
151
152
|
const onSignoutClick = async () => {
|
|
152
153
|
setShowLoading(true)
|
|
154
|
+
clearRememberedAuthEmails()
|
|
153
155
|
await logout.mutateAsync()
|
|
154
156
|
navigate('/login')
|
|
155
157
|
setShowLoading(false)
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
6
|
*/
|
|
7
|
-
import React, {useEffect, useState} from 'react'
|
|
7
|
+
import React, {useEffect, useRef, useState} from 'react'
|
|
8
8
|
import PropTypes from 'prop-types'
|
|
9
9
|
import {defineMessage, useIntl} from 'react-intl'
|
|
10
10
|
import {useForm} from 'react-hook-form'
|
|
@@ -35,8 +35,12 @@ import {noop} from '@salesforce/retail-react-app/app/utils/utils'
|
|
|
35
35
|
import {API_ERROR_MESSAGE} from '@salesforce/retail-react-app/app/constants'
|
|
36
36
|
import {
|
|
37
37
|
getAuthorizePasswordlessErrorMessage,
|
|
38
|
+
getLoginPasswordlessErrorMessage,
|
|
38
39
|
getPasswordResetErrorMessage,
|
|
39
|
-
|
|
40
|
+
MISSING_PASSWORDLESS_LOGIN_ID_ERROR,
|
|
41
|
+
readErrorResponseMessage,
|
|
42
|
+
rememberPasswordlessLoginId,
|
|
43
|
+
TOO_MANY_LOGIN_ATTEMPTS_ERROR_MESSAGE
|
|
40
44
|
} from '@salesforce/retail-react-app/app/utils/auth-utils'
|
|
41
45
|
import useNavigation from '@salesforce/retail-react-app/app/hooks/use-navigation'
|
|
42
46
|
import {usePrevious} from '@salesforce/retail-react-app/app/hooks/use-previous'
|
|
@@ -82,11 +86,13 @@ export const AuthModal = ({
|
|
|
82
86
|
const navigate = useNavigation()
|
|
83
87
|
const [currentView, setCurrentView] = useState(initialView)
|
|
84
88
|
const [isOtpAuthOpen, setIsOtpAuthOpen] = useState(false)
|
|
89
|
+
// Exact email sent to authorizePasswordless — SLAS compares login_id case-sensitively
|
|
90
|
+
const lastEmailSentRef = useRef(null)
|
|
85
91
|
const form = useForm()
|
|
86
92
|
const toast = useToast()
|
|
87
93
|
const login = useAuthHelper(AuthHelpers.LoginRegisteredUserB2C)
|
|
88
94
|
const register = useAuthHelper(AuthHelpers.Register)
|
|
89
|
-
const {locale} = useMultiSite()
|
|
95
|
+
const {site, locale} = useMultiSite()
|
|
90
96
|
|
|
91
97
|
const {getPasswordResetToken} = usePasswordReset()
|
|
92
98
|
const authorizePasswordlessLogin = useAuthHelper(AuthHelpers.AuthorizePasswordless)
|
|
@@ -103,13 +109,16 @@ export const AuthModal = ({
|
|
|
103
109
|
|
|
104
110
|
const handlePasswordlessLogin = async (email) => {
|
|
105
111
|
try {
|
|
112
|
+
const authorizeEmail = email?.trim() || ''
|
|
106
113
|
const redirectPath = window.location.pathname + (window.location.search || '')
|
|
107
114
|
await authorizePasswordlessLogin.mutateAsync({
|
|
108
|
-
userid:
|
|
115
|
+
userid: authorizeEmail,
|
|
109
116
|
mode: passwordlessMode,
|
|
110
117
|
locale: locale.id,
|
|
111
118
|
...(callbackURL && {callbackURI: `${callbackURL}?redirectUrl=${redirectPath}`})
|
|
112
119
|
})
|
|
120
|
+
lastEmailSentRef.current = authorizeEmail
|
|
121
|
+
rememberPasswordlessLoginId(authorizeEmail)
|
|
113
122
|
return {success: true}
|
|
114
123
|
} catch (error) {
|
|
115
124
|
const message = formatMessage(getAuthorizePasswordlessErrorMessage(error.message))
|
|
@@ -219,11 +228,30 @@ export const AuthModal = ({
|
|
|
219
228
|
|
|
220
229
|
const handleOtpVerification = async (pwdlessLoginToken) => {
|
|
221
230
|
try {
|
|
222
|
-
|
|
231
|
+
// Prefer the email sent to authorizePasswordless — SLAS compares login_id
|
|
232
|
+
// case-sensitively, and the form field may have been edited since then.
|
|
233
|
+
const loginId = lastEmailSentRef.current
|
|
234
|
+
if (!loginId) {
|
|
235
|
+
return {
|
|
236
|
+
success: false,
|
|
237
|
+
error: formatMessage(MISSING_PASSWORDLESS_LOGIN_ID_ERROR)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
await loginPasswordless.mutateAsync({
|
|
241
|
+
pwdlessLoginToken,
|
|
242
|
+
login_id: loginId,
|
|
243
|
+
channel_id: site.id
|
|
244
|
+
})
|
|
223
245
|
return {success: true}
|
|
224
246
|
} catch (e) {
|
|
225
|
-
|
|
226
|
-
|
|
247
|
+
if (e.response?.status === 429) {
|
|
248
|
+
return {
|
|
249
|
+
success: false,
|
|
250
|
+
error: formatMessage(TOO_MANY_LOGIN_ATTEMPTS_ERROR_MESSAGE)
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const errorMessage = await readErrorResponseMessage(e)
|
|
254
|
+
const message = formatMessage(getLoginPasswordlessErrorMessage(errorMessage))
|
|
227
255
|
return {success: false, error: message}
|
|
228
256
|
}
|
|
229
257
|
}
|
|
@@ -9,7 +9,11 @@ import {useToast} from '@salesforce/retail-react-app/app/hooks/use-toast'
|
|
|
9
9
|
import {useIntl} from 'react-intl'
|
|
10
10
|
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
|
|
11
11
|
import useMultiSite from '@salesforce/retail-react-app/app/hooks/use-multi-site'
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
clearRememberedPasswordResetEmail,
|
|
14
|
+
getPasswordlessCallbackUrl,
|
|
15
|
+
rememberPasswordResetEmail
|
|
16
|
+
} from '@salesforce/retail-react-app/app/utils/auth-utils'
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* This hook provides commerce-react-sdk hooks to simplify the reset password flow.
|
|
@@ -32,6 +36,8 @@ export const usePasswordReset = () => {
|
|
|
32
36
|
locale: locale.id,
|
|
33
37
|
...(callbackURI && {callback_uri: callbackURI})
|
|
34
38
|
})
|
|
39
|
+
// Lets the reset landing page prefill the email; the link doesn't carry it
|
|
40
|
+
rememberPasswordResetEmail(email)
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
const resetPassword = async ({email, token, newPassword}) => {
|
|
@@ -39,6 +45,7 @@ export const usePasswordReset = () => {
|
|
|
39
45
|
{user_id: email, pwd_action_token: token, new_password: newPassword},
|
|
40
46
|
{
|
|
41
47
|
onSuccess: () => {
|
|
48
|
+
clearRememberedPasswordResetEmail()
|
|
42
49
|
showToast({
|
|
43
50
|
title: formatMessage({
|
|
44
51
|
defaultMessage: 'Password Reset Success',
|
|
@@ -11,6 +11,7 @@ import {renderWithProviders} from '@salesforce/retail-react-app/app/utils/test-u
|
|
|
11
11
|
import {usePasswordReset} from '@salesforce/retail-react-app/app/hooks/use-password-reset'
|
|
12
12
|
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
|
|
13
13
|
import mockConfig from '@salesforce/retail-react-app/config/mocks/default'
|
|
14
|
+
import {getRememberedPasswordResetEmail} from '@salesforce/retail-react-app/app/utils/auth-utils'
|
|
14
15
|
|
|
15
16
|
const mockEmail = 'test@email.com'
|
|
16
17
|
const mockToken = '123456'
|
|
@@ -69,6 +70,7 @@ useAuthHelper.mockImplementation((param) => {
|
|
|
69
70
|
|
|
70
71
|
beforeEach(() => {
|
|
71
72
|
jest.clearAllMocks()
|
|
73
|
+
window.localStorage.clear()
|
|
72
74
|
getConfig.mockImplementation(() => mockConfig)
|
|
73
75
|
})
|
|
74
76
|
|
|
@@ -156,6 +158,49 @@ describe('usePasswordReset', () => {
|
|
|
156
158
|
})
|
|
157
159
|
})
|
|
158
160
|
|
|
161
|
+
test('getPasswordResetToken remembers the email after the request succeeds', async () => {
|
|
162
|
+
getPasswordResetToken.mutateAsync.mockResolvedValue({})
|
|
163
|
+
renderWithProviders(<MockComponent />)
|
|
164
|
+
|
|
165
|
+
await fireEvent.click(screen.getByTestId('get-password-reset-token'))
|
|
166
|
+
await waitFor(() => {
|
|
167
|
+
expect(getRememberedPasswordResetEmail()).toBe(mockEmail)
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
test('getPasswordResetToken does not remember the email when the request fails', async () => {
|
|
172
|
+
const MockFailingComponent = () => {
|
|
173
|
+
const {getPasswordResetToken: request} = usePasswordReset()
|
|
174
|
+
return (
|
|
175
|
+
<button data-testid="request" onClick={() => request(mockEmail).catch(() => {})} />
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
getPasswordResetToken.mutateAsync.mockRejectedValue(new Error('failed'))
|
|
179
|
+
renderWithProviders(<MockFailingComponent />)
|
|
180
|
+
|
|
181
|
+
await fireEvent.click(screen.getByTestId('request'))
|
|
182
|
+
await waitFor(() => {
|
|
183
|
+
expect(getPasswordResetToken.mutateAsync).toHaveBeenCalled()
|
|
184
|
+
})
|
|
185
|
+
expect(getRememberedPasswordResetEmail()).toBeNull()
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
test('resetPassword clears the remembered email on success', async () => {
|
|
189
|
+
resetPassword.mutateAsync.mockResolvedValue({})
|
|
190
|
+
window.localStorage.setItem(
|
|
191
|
+
'pwd_reset_email',
|
|
192
|
+
JSON.stringify({loginId: mockEmail, expiresAt: Date.now() + 60000})
|
|
193
|
+
)
|
|
194
|
+
renderWithProviders(<MockComponent />)
|
|
195
|
+
|
|
196
|
+
await fireEvent.click(screen.getByTestId('reset-password'))
|
|
197
|
+
await waitFor(() => {
|
|
198
|
+
expect(resetPassword.mutateAsync).toHaveBeenCalled()
|
|
199
|
+
})
|
|
200
|
+
resetPassword.mutateAsync.mock.calls[0][1].onSuccess()
|
|
201
|
+
expect(getRememberedPasswordResetEmail()).toBeNull()
|
|
202
|
+
})
|
|
203
|
+
|
|
159
204
|
test('resetPasswordLandingPath is returned', () => {
|
|
160
205
|
renderWithProviders(<MockComponent />)
|
|
161
206
|
expect(screen.getByTestId('reset-password-landing-path')).toHaveTextContent(
|
|
@@ -47,6 +47,7 @@ import {useCurrentCustomer} from '@salesforce/retail-react-app/app/hooks/use-cur
|
|
|
47
47
|
import {isHydrated} from '@salesforce/retail-react-app/app/utils/utils'
|
|
48
48
|
import AccountPayments from '@salesforce/retail-react-app/app/pages/account/payments'
|
|
49
49
|
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
|
|
50
|
+
import {clearRememberedAuthEmails} from '@salesforce/retail-react-app/app/utils/auth-utils'
|
|
50
51
|
|
|
51
52
|
const onClient = typeof window !== 'undefined'
|
|
52
53
|
const LogoutButton = ({onClick}) => {
|
|
@@ -116,6 +117,7 @@ const Account = () => {
|
|
|
116
117
|
|
|
117
118
|
const onSignoutClick = async () => {
|
|
118
119
|
setShowLoading(true)
|
|
120
|
+
clearRememberedAuthEmails()
|
|
119
121
|
await logout.mutateAsync()
|
|
120
122
|
navigate('/login')
|
|
121
123
|
}
|
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
} from '@salesforce/commerce-sdk-react'
|
|
49
49
|
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
|
|
50
50
|
import {
|
|
51
|
+
clearRememberedAuthEmails,
|
|
51
52
|
getPasswordlessCallbackUrl,
|
|
52
53
|
getAuthorizePasswordlessErrorMessage
|
|
53
54
|
} from '@salesforce/retail-react-app/app/utils/auth-utils'
|
|
@@ -264,6 +265,7 @@ const ContactInfo = ({isSocialEnabled = false, isPasswordlessEnabled = false, id
|
|
|
264
265
|
isOpen={signOutConfirmDialogIsOpen}
|
|
265
266
|
onClose={() => setSignOutConfirmDialogIsOpen(false)}
|
|
266
267
|
onConfirm={async () => {
|
|
268
|
+
clearRememberedAuthEmails()
|
|
267
269
|
await logout.mutateAsync()
|
|
268
270
|
navigate('/login')
|
|
269
271
|
setSignOutConfirmDialogIsOpen(false)
|
|
@@ -50,14 +50,19 @@ import {
|
|
|
50
50
|
useShopperCustomersMutation
|
|
51
51
|
} from '@salesforce/commerce-sdk-react'
|
|
52
52
|
import {API_ERROR_MESSAGE} from '@salesforce/retail-react-app/app/constants'
|
|
53
|
-
import {
|
|
53
|
+
import {
|
|
54
|
+
clearRememberedAuthEmails,
|
|
55
|
+
getAuthorizePasswordlessErrorMessage,
|
|
56
|
+
getPasswordlessCallbackUrl,
|
|
57
|
+
MISSING_PASSWORDLESS_LOGIN_ID_ERROR,
|
|
58
|
+
rememberPasswordlessLoginId
|
|
59
|
+
} from '@salesforce/retail-react-app/app/utils/auth-utils'
|
|
54
60
|
import {isValidEmail} from '@salesforce/retail-react-app/app/utils/email-utils'
|
|
55
61
|
import {formatPhoneNumber} from '@salesforce/retail-react-app/app/utils/phone-utils'
|
|
56
62
|
import useMultiSite from '@salesforce/retail-react-app/app/hooks/use-multi-site'
|
|
57
63
|
import {isPickupShipment} from '@salesforce/retail-react-app/app/utils/shipment-utils'
|
|
58
64
|
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
|
|
59
65
|
import {useLocation} from 'react-router-dom'
|
|
60
|
-
import {getPasswordlessCallbackUrl} from '@salesforce/retail-react-app/app/utils/auth-utils'
|
|
61
66
|
|
|
62
67
|
const ContactInfo = ({isSocialEnabled = false, idps = [], onRegisteredUserChoseGuest}) => {
|
|
63
68
|
const {formatMessage} = useIntl()
|
|
@@ -76,7 +81,7 @@ const ContactInfo = ({isSocialEnabled = false, idps = [], onRegisteredUserChoseG
|
|
|
76
81
|
const updateBillingAddressForBasket = useShopperBasketsMutation('updateBillingAddressForBasket')
|
|
77
82
|
const authorizePasswordlessLogin = useAuthHelper(AuthHelpers.AuthorizePasswordless)
|
|
78
83
|
const loginPasswordless = useAuthHelper(AuthHelpers.LoginPasswordlessUser)
|
|
79
|
-
const {locale} = useMultiSite()
|
|
84
|
+
const {site, locale} = useMultiSite()
|
|
80
85
|
const passwordlessConfig = getConfig().app.login?.passwordless
|
|
81
86
|
const callbackURL = getPasswordlessCallbackUrl(passwordlessConfig?.callbackURI)
|
|
82
87
|
const redirectPath = location.pathname + location.search
|
|
@@ -219,11 +224,13 @@ const ContactInfo = ({isSocialEnabled = false, idps = [], onRegisteredUserChoseG
|
|
|
219
224
|
|
|
220
225
|
// Handle sending OTP email
|
|
221
226
|
const handleSendEmailOtp = async (email, isResend = false) => {
|
|
222
|
-
//
|
|
223
|
-
const
|
|
227
|
+
// Preserve exact casing for SLAS (login_id is case-sensitive); normalize only for dedupe.
|
|
228
|
+
const authorizeEmail = email?.trim() || ''
|
|
229
|
+
const normalizedEmail = authorizeEmail.toLowerCase()
|
|
230
|
+
const lastNormalized = lastEmailSentRef.current?.trim().toLowerCase() || ''
|
|
224
231
|
|
|
225
232
|
// Skip if email hasn't changed from the last one we sent (unless user requested)
|
|
226
|
-
if (!isResend &&
|
|
233
|
+
if (!isResend && lastNormalized && lastNormalized === normalizedEmail) {
|
|
227
234
|
// Return cached result if we have one
|
|
228
235
|
if (otpSendPromiseRef.current) {
|
|
229
236
|
return otpSendPromiseRef.current
|
|
@@ -243,7 +250,7 @@ const ContactInfo = ({isSocialEnabled = false, idps = [], onRegisteredUserChoseG
|
|
|
243
250
|
otpSendPromiseRef.current = (async () => {
|
|
244
251
|
try {
|
|
245
252
|
await authorizePasswordlessLogin.mutateAsync({
|
|
246
|
-
userid:
|
|
253
|
+
userid: authorizeEmail,
|
|
247
254
|
mode: passwordlessConfig?.mode,
|
|
248
255
|
locale: locale?.id,
|
|
249
256
|
...(callbackURL && {callbackURI: `${callbackURL}?redirectUrl=${redirectPath}`})
|
|
@@ -251,8 +258,9 @@ const ContactInfo = ({isSocialEnabled = false, idps = [], onRegisteredUserChoseG
|
|
|
251
258
|
// Only open modal if API call succeeds
|
|
252
259
|
onOtpModalOpen()
|
|
253
260
|
otpFromContactRef.current = true
|
|
254
|
-
//
|
|
255
|
-
lastEmailSentRef.current =
|
|
261
|
+
// Store the exact email sent to authorize — required for login_id on verify
|
|
262
|
+
lastEmailSentRef.current = authorizeEmail
|
|
263
|
+
rememberPasswordlessLoginId(authorizeEmail)
|
|
256
264
|
return {isRegistered: true}
|
|
257
265
|
} catch (error) {
|
|
258
266
|
// 404 = email not registered (guest); treat as guest and continue
|
|
@@ -270,7 +278,7 @@ const ContactInfo = ({isSocialEnabled = false, idps = [], onRegisteredUserChoseG
|
|
|
270
278
|
}
|
|
271
279
|
}
|
|
272
280
|
// Update the last email sent ref even on error to prevent retrying immediately
|
|
273
|
-
lastEmailSentRef.current =
|
|
281
|
+
lastEmailSentRef.current = authorizeEmail
|
|
274
282
|
return {isRegistered: false}
|
|
275
283
|
} finally {
|
|
276
284
|
setIsCheckingEmail(false)
|
|
@@ -304,7 +312,20 @@ const ContactInfo = ({isSocialEnabled = false, idps = [], onRegisteredUserChoseG
|
|
|
304
312
|
try {
|
|
305
313
|
// Prevent post-auth recovery effect from also attempting merge in this flow
|
|
306
314
|
hasAttemptedRecoveryRef.current = true
|
|
307
|
-
|
|
315
|
+
// Prefer the email sent to authorizePasswordless — SLAS compares login_id
|
|
316
|
+
// case-sensitively, and the form field may have been edited since then.
|
|
317
|
+
const loginId = lastEmailSentRef.current
|
|
318
|
+
if (!loginId) {
|
|
319
|
+
return {
|
|
320
|
+
success: false,
|
|
321
|
+
error: formatMessage(MISSING_PASSWORDLESS_LOGIN_ID_ERROR)
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
await loginPasswordless.mutateAsync({
|
|
325
|
+
pwdlessLoginToken: otpCode,
|
|
326
|
+
login_id: loginId,
|
|
327
|
+
channel_id: site.id
|
|
328
|
+
})
|
|
308
329
|
|
|
309
330
|
// Successful OTP verification - user is now logged in
|
|
310
331
|
const hasBasketItem = basket.productItems?.length > 0
|
|
@@ -325,9 +346,8 @@ const ContactInfo = ({isSocialEnabled = false, idps = [], onRegisteredUserChoseG
|
|
|
325
346
|
basketId = refreshed?.data?.basketId || basketId
|
|
326
347
|
}
|
|
327
348
|
|
|
328
|
-
// Update basket with email after successful OTP verification
|
|
329
|
-
const email =
|
|
330
|
-
form.getValues('email') || (emailRef.current && emailRef.current.value) || ''
|
|
349
|
+
// Update basket with the authorize-time email after successful OTP verification
|
|
350
|
+
const email = lastEmailSentRef.current || form.getValues('email') || ''
|
|
331
351
|
if (basketId && email) {
|
|
332
352
|
try {
|
|
333
353
|
await updateCustomerForBasket.mutateAsync({
|
|
@@ -723,6 +743,7 @@ const ContactInfo = ({isSocialEnabled = false, idps = [], onRegisteredUserChoseG
|
|
|
723
743
|
isOpen={signOutConfirmDialogIsOpen}
|
|
724
744
|
onClose={() => setSignOutConfirmDialogIsOpen(false)}
|
|
725
745
|
onConfirm={async () => {
|
|
746
|
+
clearRememberedAuthEmails()
|
|
726
747
|
await logout.mutateAsync()
|
|
727
748
|
setSignOutConfirmDialogIsOpen(false)
|
|
728
749
|
navigate('/')
|
|
@@ -25,7 +25,14 @@ import {useCurrentBasket} from '@salesforce/retail-react-app/app/hooks/use-curre
|
|
|
25
25
|
import {useCustomerType, useAuthHelper, AuthHelpers} from '@salesforce/commerce-sdk-react'
|
|
26
26
|
import {useShopperCustomersMutation} from '@salesforce/commerce-sdk-react'
|
|
27
27
|
import useMultiSite from '@salesforce/retail-react-app/app/hooks/use-multi-site'
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
getLoginPasswordlessErrorMessage,
|
|
30
|
+
getPasswordlessCallbackUrl,
|
|
31
|
+
MISSING_PASSWORDLESS_LOGIN_ID_ERROR,
|
|
32
|
+
readErrorResponseMessage,
|
|
33
|
+
rememberPasswordlessLoginId,
|
|
34
|
+
TOO_MANY_LOGIN_ATTEMPTS_ERROR_MESSAGE
|
|
35
|
+
} from '@salesforce/retail-react-app/app/utils/auth-utils'
|
|
29
36
|
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
|
|
30
37
|
import {useCheckout} from '@salesforce/retail-react-app/app/pages/checkout-one-click/util/checkout-context'
|
|
31
38
|
import {useToast} from '@salesforce/retail-react-app/app/hooks/use-toast'
|
|
@@ -51,7 +58,7 @@ export default function UserRegistration({
|
|
|
51
58
|
const {isGuest} = useCustomerType()
|
|
52
59
|
const authorizePasswordlessLogin = useAuthHelper(AuthHelpers.AuthorizePasswordless)
|
|
53
60
|
const loginPasswordless = useAuthHelper(AuthHelpers.LoginPasswordlessUser)
|
|
54
|
-
const {locale} = useMultiSite()
|
|
61
|
+
const {site, locale} = useMultiSite()
|
|
55
62
|
const {formatMessage} = useIntl()
|
|
56
63
|
const showToast = useToast()
|
|
57
64
|
const createCustomerAddress = useShopperCustomersMutation('createCustomerAddress')
|
|
@@ -59,6 +66,8 @@ export default function UserRegistration({
|
|
|
59
66
|
|
|
60
67
|
const {isOpen: isOtpOpen, onOpen: onOtpOpen, onClose: onOtpClose} = useDisclosure()
|
|
61
68
|
const otpSentRef = useRef(false)
|
|
69
|
+
// Exact email sent to authorizePasswordless — SLAS compares login_id case-sensitively
|
|
70
|
+
const lastEmailSentRef = useRef(null)
|
|
62
71
|
const [registrationSucceeded, setRegistrationSucceeded] = useState(false)
|
|
63
72
|
const [isLoadingOtp, setIsLoadingOtp] = useState(false)
|
|
64
73
|
|
|
@@ -87,18 +96,21 @@ export default function UserRegistration({
|
|
|
87
96
|
}
|
|
88
97
|
// Kick off OTP for guests when they opt in
|
|
89
98
|
if (checked && isGuest && basket?.customerInfo?.email && !otpSentRef.current) {
|
|
99
|
+
const authorizeEmail = basket.customerInfo.email
|
|
90
100
|
setIsLoadingOtp(true)
|
|
91
101
|
if (onLoadingChange) onLoadingChange(true)
|
|
92
102
|
try {
|
|
93
103
|
await authorizePasswordlessLogin.mutateAsync({
|
|
94
|
-
userid:
|
|
104
|
+
userid: authorizeEmail,
|
|
95
105
|
mode: 'callback',
|
|
96
106
|
...(registrationCallbackURL && {callbackURI: registrationCallbackURL}),
|
|
97
107
|
locale: locale?.id,
|
|
98
108
|
register_customer: true,
|
|
99
|
-
last_name:
|
|
100
|
-
email:
|
|
109
|
+
last_name: authorizeEmail,
|
|
110
|
+
email: authorizeEmail
|
|
101
111
|
})
|
|
112
|
+
lastEmailSentRef.current = authorizeEmail
|
|
113
|
+
rememberPasswordlessLoginId(authorizeEmail)
|
|
102
114
|
otpSentRef.current = true
|
|
103
115
|
onOtpOpen()
|
|
104
116
|
} catch (_e) {
|
|
@@ -179,10 +191,20 @@ export default function UserRegistration({
|
|
|
179
191
|
}
|
|
180
192
|
|
|
181
193
|
const handleOtpVerification = async (otpCode) => {
|
|
194
|
+
const loginId = lastEmailSentRef.current || basket?.customerInfo?.email
|
|
195
|
+
if (!loginId) {
|
|
196
|
+
return {
|
|
197
|
+
success: false,
|
|
198
|
+
error: formatMessage(MISSING_PASSWORDLESS_LOGIN_ID_ERROR)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
182
202
|
try {
|
|
183
203
|
const token = await loginPasswordless.mutateAsync({
|
|
184
204
|
pwdlessLoginToken: otpCode,
|
|
185
|
-
register_customer: true
|
|
205
|
+
register_customer: true,
|
|
206
|
+
login_id: loginId,
|
|
207
|
+
channel_id: site.id
|
|
186
208
|
})
|
|
187
209
|
|
|
188
210
|
const customerId = token?.customer_id || token?.customerId
|
|
@@ -195,10 +217,20 @@ export default function UserRegistration({
|
|
|
195
217
|
}
|
|
196
218
|
handleOtpClose()
|
|
197
219
|
setRegistrationSucceeded(true)
|
|
198
|
-
|
|
199
|
-
|
|
220
|
+
return {success: true}
|
|
221
|
+
} catch (e) {
|
|
222
|
+
if (e.response?.status === 429) {
|
|
223
|
+
return {
|
|
224
|
+
success: false,
|
|
225
|
+
error: formatMessage(TOO_MANY_LOGIN_ATTEMPTS_ERROR_MESSAGE)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const errorMessage = await readErrorResponseMessage(e)
|
|
229
|
+
return {
|
|
230
|
+
success: false,
|
|
231
|
+
error: formatMessage(getLoginPasswordlessErrorMessage(errorMessage))
|
|
232
|
+
}
|
|
200
233
|
}
|
|
201
|
-
return {success: true}
|
|
202
234
|
}
|
|
203
235
|
|
|
204
236
|
// Hide the form if the "Checkout as Guest" button was clicked
|
|
@@ -323,7 +355,7 @@ export default function UserRegistration({
|
|
|
323
355
|
setValue: () => {}
|
|
324
356
|
}}
|
|
325
357
|
handleSendEmailOtp={async (email) => {
|
|
326
|
-
|
|
358
|
+
await authorizePasswordlessLogin.mutateAsync({
|
|
327
359
|
userid: email,
|
|
328
360
|
mode: 'callback',
|
|
329
361
|
...(registrationCallbackURL && {callbackURI: registrationCallbackURL}),
|
|
@@ -332,6 +364,8 @@ export default function UserRegistration({
|
|
|
332
364
|
last_name: email,
|
|
333
365
|
email
|
|
334
366
|
})
|
|
367
|
+
lastEmailSentRef.current = email
|
|
368
|
+
rememberPasswordlessLoginId(email)
|
|
335
369
|
}}
|
|
336
370
|
handleOtpVerification={handleOtpVerification}
|
|
337
371
|
/>
|
|
@@ -399,7 +399,9 @@ describe('UserRegistration', () => {
|
|
|
399
399
|
await waitFor(() => {
|
|
400
400
|
expect(loginPasswordless.mutateAsync).toHaveBeenCalledWith({
|
|
401
401
|
pwdlessLoginToken: 'otp-123',
|
|
402
|
-
register_customer: true
|
|
402
|
+
register_customer: true,
|
|
403
|
+
login_id: 'test@example.com',
|
|
404
|
+
channel_id: 'RefArch'
|
|
403
405
|
})
|
|
404
406
|
})
|
|
405
407
|
})
|