diff --git a/apps/storefront/src/components/RegisteredCloseButton.tsx b/apps/storefront/src/components/RegisteredCloseButton.tsx index 76fdc701..5f4dd123 100644 --- a/apps/storefront/src/components/RegisteredCloseButton.tsx +++ b/apps/storefront/src/components/RegisteredCloseButton.tsx @@ -34,7 +34,9 @@ export function RegisteredCloseButton(props: CloseButtonProps) { state: { isCheckout, isCloseGotoBCHome, + isLoginStatusChange, }, + dispatch, } = useContext(GlobaledContext) const handleCloseForm = () => { @@ -45,6 +47,16 @@ export function RegisteredCloseButton(props: CloseButtonProps) { isOpen: false, openUrl: '', }) + + if (isLoginStatusChange) { + window.location.reload() + dispatch({ + type: 'common', + payload: { + isLoginStatusChange: false, + }, + }) + } } } diff --git a/apps/storefront/src/pages/login/Login.tsx b/apps/storefront/src/pages/login/Login.tsx index b074e3e1..29b2d197 100644 --- a/apps/storefront/src/pages/login/Login.tsx +++ b/apps/storefront/src/pages/login/Login.tsx @@ -33,6 +33,7 @@ import { import { getCurrentCustomerInfo, + clearCurrentCustomerInfo, } from '@/utils' import { @@ -155,6 +156,8 @@ export default function Login() { isCloseGotoBCHome: true, }, }) + + clearCurrentCustomerInfo(dispatch) } // setChannelId(getChannelId) @@ -239,6 +242,13 @@ export default function Login() { } else { const info = await getCurrentCustomerInfo(dispatch) + dispatch({ + type: 'common', + payload: { + isLoginStatusChange: true, + }, + }) + if (info?.userType === 3 && info?.role === 3) { navigate('/dashboard') } else { diff --git a/apps/storefront/src/shared/global/context/config.ts b/apps/storefront/src/shared/global/context/config.ts index 1d58cac7..5c2bcb76 100644 --- a/apps/storefront/src/shared/global/context/config.ts +++ b/apps/storefront/src/shared/global/context/config.ts @@ -20,6 +20,7 @@ export interface GlobalState { BcToken: string, isB2BUser: boolean, isLogin: boolean, + isLoginStatusChange: boolean, customerId: number | string, customer?: CustomerInfo, emailAddress: string, @@ -32,6 +33,7 @@ export const initState = { BcToken: B3SStorage.get('BcToken') || '', isB2BUser: B3SStorage.get('isB2BUser') || false, isLogin: false, + isLoginStatusChange: false, customerId: B3SStorage.get('B3CustomerId') || '', emailAddress: B3SStorage.get('B3EmailAddress') || '', role: B3SStorage.get('B3Role') || '', diff --git a/apps/storefront/src/utils/index.ts b/apps/storefront/src/utils/index.ts index 7b859aa6..65e4519e 100644 --- a/apps/storefront/src/utils/index.ts +++ b/apps/storefront/src/utils/index.ts @@ -21,6 +21,7 @@ import { getChannelId, loginInfo, getCurrentCustomerInfo, + clearCurrentCustomerInfo, } from './loginInfo' export { @@ -34,4 +35,5 @@ export { loginInfo, getChannelId, getCurrentCustomerInfo, + clearCurrentCustomerInfo, } diff --git a/apps/storefront/src/utils/loginInfo.ts b/apps/storefront/src/utils/loginInfo.ts index 4cd86543..47471034 100644 --- a/apps/storefront/src/utils/loginInfo.ts +++ b/apps/storefront/src/utils/loginInfo.ts @@ -89,6 +89,30 @@ export const loginInfo = async () => { B3SStorage.set('BcToken', token) } +export const clearCurrentCustomerInfo = async (dispatch: DispatchProps) => { + B3SStorage.set('B3CustomerInfo', {}) + B3SStorage.set('B3CustomerId', '') + B3SStorage.set('B3EmailAddress', '') + B3SStorage.set('B3Role', 0) + B3SStorage.set('isB2BUser', false) + + dispatch({ + type: 'common', + payload: { + isB2BUser: false, + role: 0, + customerId: '', + customer: { + phoneNumber: '', + firstName: '', + lastName: '', + emailAddress: '', + }, + emailAddress: '', + }, + }) +} + export const getCurrentCustomerInfo = async (dispatch: DispatchProps) => { try { const { @@ -154,5 +178,6 @@ export const getCurrentCustomerInfo = async (dispatch: DispatchProps) => { } catch (error) { // eslint-disable-next-line no-console console.log(error) + clearCurrentCustomerInfo(dispatch) } }