Skip to content

Commit 4917ef3

Browse files
committed
check for invalid token error in passwordless login
1 parent dd8f3e9 commit 4917ef3

File tree

1 file changed

+13
-8
lines changed
  • packages/template-retail-react-app/app/pages/login

1 file changed

+13
-8
lines changed

packages/template-retail-react-app/app/pages/login/index.jsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,21 @@ const Login = ({initialView = LOGIN_VIEW}) => {
148148
// executing a passwordless login attempt using the token. The process waits for the
149149
// customer baskets to be loaded to guarantee proper basket merging.
150150
useEffect(() => {
151-
if (path === PASSWORDLESS_LOGIN_LANDING_PATH && isSuccessCustomerBaskets) {
151+
if (path === PASSWORDLESS_LOGIN_LANDING_PATH) {
152152
const token = queryParams.get('token')
153-
try {
154-
loginPasswordless.mutate({pwdlessLoginToken: token})
155-
} catch (e) {
156-
const message = /Unauthorized/i.test(e.message)
157-
? formatMessage(INVALID_TOKEN_ERROR_MESSAGE)
158-
: formatMessage(API_ERROR_MESSAGE)
159-
form.setError('global', {type: 'manual', message})
153+
154+
const passwordlessLogin = async() => {
155+
try {
156+
const res = await loginPasswordless.mutateAsync({pwdlessLoginToken: token})
157+
} catch (e) {
158+
const errorData = await e.response?.json()
159+
const message = /invalid token/i.test(errorData.message)
160+
? formatMessage(INVALID_TOKEN_ERROR_MESSAGE)
161+
: formatMessage(API_ERROR_MESSAGE)
162+
form.setError('global', {type: 'manual', message})
163+
}
160164
}
165+
passwordlessLogin()
161166
}
162167
}, [path, isSuccessCustomerBaskets])
163168

0 commit comments

Comments
 (0)