Skip to content

Commit

Permalink
fix: login failure verification
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 authored and bc-micah committed Nov 10, 2023
1 parent 5064e35 commit 38ca255
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
1 change: 0 additions & 1 deletion apps/storefront/src/pages/accountSetting/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ function sendEmail(data: any, extraFields: any) {
(field: Partial<Fields>) => field.name === item.bcLabel
).value
formData.append(`FormField[1][${key}]`, val)
console.log(key, val)
}
})
}
Expand Down
44 changes: 22 additions & 22 deletions apps/storefront/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,16 @@ import {
getBCForcePasswordReset,
superAdminEndMasquerade,
} from '@/shared/service/b2b'
import {
bcLogin,
// bcLogoutLogin,
} from '@/shared/service/bc'
import {
B3SStorage,
clearCurrentCustomerInfo,
getCurrentCustomerInfo,
} from '@/utils'
import { bcLogin } from '@/shared/service/bc'
import { B3SStorage, getCurrentCustomerInfo } from '@/utils'

import LoginWidget from './component/LoginWidget'
import {
getLoginFlag,
loginCheckout,
LoginConfig,
LoginInfoInit,
logout,
} from './config'
import LoginForm from './LoginForm'
import LoginPanel from './LoginPanel'
Expand Down Expand Up @@ -87,7 +81,6 @@ export default function Login(props: RegisteredProps) {
salesRepCompanyId = 0,
isAgenting,
registerEnabled,
customerId,
},
dispatch,
} = useContext(GlobaledContext)
Expand Down Expand Up @@ -137,31 +130,38 @@ export default function Login(props: RegisteredProps) {

const loginFlag = getLoginFlag(search, 'loginFlag')
const showTipInfo = getLoginFlag(search, 'showTip') !== 'false'
const closeIsLogout = getLoginFlag(search, 'closeIsLogout') === '1'

setShowTipInfo(showTipInfo)

if (loginFlag) setLoginFlag(loginFlag)

if (loginFlag === '3') {
// await bcLogoutLogin()
const isLogout = B3SStorage.get('isLogout') === '1'
if (loginFlag === '3' && !isLogout) {
const isLogout = await logout()

if (!customerId) return
if (!isLogout) return

if (isAgenting) {
await superAdminEndMasquerade(+salesRepCompanyId, +B3UserId)
}
dispatch({
type: 'common',
payload: {
isCloseGotoBCHome: true,
},
})

// SUP-1282 Clear sessionStorage to allow visitors to display the checkout page
window.sessionStorage.clear()

clearCurrentCustomerInfo(dispatch)
await fetch('/login.php?action=logout')
B3SStorage.set('isLogout', '1')

if (window.location.pathname.includes('login.php')) {
window.location.reload()
} else {
window.location.href = '/login.php/#/login?loginFlag=3'
}

return
}

if (closeIsLogout) {
B3SStorage.delete('isLogout')
}

setLoginInfo(Info)
Expand All @@ -172,7 +172,7 @@ export default function Login(props: RegisteredProps) {
}

init()
}, [loginPageButton, loginPageDisplay, loginPageHtml])
}, [loginPageButton, loginPageDisplay, loginPageHtml, location])

const tipInfo = (loginFlag: string, email = '') => {
let str = ''
Expand Down
14 changes: 14 additions & 0 deletions apps/storefront/src/pages/login/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,17 @@ export const getBCChannelId = (storeSitesany: Array<ChannelIdProps>) => {

return channelId
}

export const logout = () => new Promise<boolean>((resolve, reject) => {
fetch('/login.php?action=logout').then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok')
}
return response.text()
}).then((responseData) => {
const isFlag = responseData.includes('alertBox--success')
resolve(isFlag)
}).catch(e => {
reject(e)
})
})
5 changes: 5 additions & 0 deletions apps/storefront/src/shared/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { lazy } from 'react'
import { matchPath } from 'react-router-dom'

import { GlobalState, QuoteConfigProps } from '@/shared/global/context/config'
import { B3SStorage } from '@/utils'

const OrderList = lazy(() => import('../../pages/order/MyOrder'))

Expand Down Expand Up @@ -382,6 +383,10 @@ const gotoAllowedAppPage = (
gotoPage: (url: string) => void,
isAccountEnter?: boolean
) => {
if (B3SStorage.get('isLogout') === '1') {
gotoPage('/login?loginFlag=3&&closeIsLogout=1')
return
}
const { hash, pathname } = window.location
let url = hash.split('#')[1] || ''
if (
Expand Down

0 comments on commit 38ca255

Please sign in to comment.