@@ -15,7 +15,7 @@ import {jwtDecode, JwtPayload} from 'jwt-decode'
1515import { ApiClientConfigParams , Prettify , RemoveStringIndex } from '../hooks/types'
1616import { BaseStorage , LocalStorage , CookieStorage , MemoryStorage , StorageType } from './storage'
1717import { CustomerType } from '../hooks/useCustomerType'
18- import { onClient } from '../utils'
18+ import { getParentOrigin , isOriginTrusted , onClient } from '../utils'
1919
2020type TokenResponse = ShopperLoginTypes . TokenResponse
2121type Helpers = typeof helpers
@@ -67,6 +67,8 @@ type AuthDataMap = Record<
6767 }
6868>
6969
70+ const isParentTrusted = isOriginTrusted ( getParentOrigin ( ) )
71+
7072/**
7173 * A map of the data that this auth module stores. This maps the name of the property to
7274 * the storage type and the key when stored in that storage. You can also pass in a "callback"
@@ -107,16 +109,16 @@ const DATA_MAP: AuthDataMap = {
107109 } ,
108110 refresh_token_guest : {
109111 storageType : 'cookie' ,
110- key : 'cc-nx-g' ,
112+ key : isParentTrusted ? 'cc-nx-g-iframe' : 'cc-nx-g' ,
111113 callback : ( store ) => {
112- store . delete ( 'cc-nx' )
114+ store . delete ( isParentTrusted ? 'cc-nx-iframe' : 'cc-nx' )
113115 }
114116 } ,
115117 refresh_token_registered : {
116118 storageType : 'cookie' ,
117- key : 'cc-nx' ,
119+ key : isParentTrusted ? 'cc-nx-iframe' : 'cc-nx' ,
118120 callback : ( store ) => {
119- store . delete ( 'cc-nx-g' )
121+ store . delete ( isParentTrusted ? 'cc-nx-g-iframe' : 'cc-nx-g' )
120122 }
121123 } ,
122124 refresh_token_expires_in : {
@@ -129,16 +131,16 @@ const DATA_MAP: AuthDataMap = {
129131 // This triggers a new fetch for access_token using the current refresh_token from cookie storage and makes sure customer auth state is always in sync between SFRA and PWA sites in a hybrid setup.
130132 refresh_token_guest_copy : {
131133 storageType : 'local' ,
132- key : 'cc-nx-g' ,
134+ key : isParentTrusted ? 'cc-nx-g-iframe' : 'cc-nx-g' ,
133135 callback : ( store ) => {
134- store . delete ( 'cc-nx' )
136+ store . delete ( isParentTrusted ? 'cc-nx-iframe' : 'cc-nx' )
135137 }
136138 } ,
137139 refresh_token_registered_copy : {
138140 storageType : 'local' ,
139- key : 'cc-nx' ,
141+ key : isParentTrusted ? 'cc-nx-iframe' : 'cc-nx' ,
140142 callback : ( store ) => {
141- store . delete ( 'cc-nx-g' )
143+ store . delete ( isParentTrusted ? 'cc-nx-g-iframe' : 'cc-nx-g' )
142144 }
143145 } ,
144146 customer_type : {
0 commit comments