Skip to content

Commit 139d4c4

Browse files
fix: logout issue for add passkey pop up while entering password (#1069)
* fix: logout issue for add passkey pop up while entering password Signed-off-by: pranalidhanavade <[email protected]> * fix: logout issue for add passkey pop up while entering password Signed-off-by: pranalidhanavade <[email protected]> --------- Signed-off-by: pranalidhanavade <[email protected]>
1 parent a771519 commit 139d4c4

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

nextjs/src/features/passkey/PassKeyAddDevice.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import * as yup from 'yup'
44

5-
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
65
import {
76
Dialog,
87
DialogContent,
@@ -13,6 +12,7 @@ import { Eye, EyeOff } from 'lucide-react'
1312
import { Field, Form, Formik } from 'formik'
1413
import { useEffect, useState } from 'react'
1514

15+
import { AlertComponent } from '@/components/AlertComponent'
1616
import { AxiosResponse } from 'axios'
1717
import { Button } from '@/components/ui/button'
1818
import { Input } from '@/components/ui/input'
@@ -39,7 +39,6 @@ export default function PasskeyAddDevice({
3939
registerWithPasskey,
4040
}: PasskeyAddDeviceProps): React.JSX.Element {
4141
const [fidoUserError, setFidoUserError] = useState<string | null>(null)
42-
const [success] = useState<string | null>(null)
4342
const [nextStep, setNextStep] = useState(false)
4443
const [passwordVisible, setPasswordVisible] = useState(false)
4544
const [userEmail, setUserEmail] = useState('')
@@ -60,7 +59,7 @@ export default function PasskeyAddDevice({
6059
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
6160
setNextStep(true)
6261
} else if (res.toString().includes('401')) {
63-
setFidoUserError('Invalid Credentials')
62+
setFidoUserError(res as string)
6463
} else {
6564
setFidoUserError(res as string)
6665
}
@@ -83,12 +82,17 @@ export default function PasskeyAddDevice({
8382
<DialogTitle>Create Passkey</DialogTitle>
8483
</DialogHeader>
8584

86-
{fidoUserError || success ? (
87-
<Alert variant={fidoUserError ? 'destructive' : 'default'}>
88-
<AlertTitle>{fidoUserError ? 'Error' : 'Success'}</AlertTitle>
89-
<AlertDescription>{fidoUserError || success}</AlertDescription>
90-
</Alert>
91-
) : null}
85+
{fidoUserError && (
86+
<div className="w-full" role="alert">
87+
<AlertComponent
88+
message={fidoUserError}
89+
type="failure"
90+
onAlertClose={() => {
91+
setFidoUserError(null)
92+
}}
93+
/>
94+
</div>
95+
)}
9296

9397
{!nextStep ? (
9498
<Formik

nextjs/src/services/axiosIntercepter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ instance.interceptors.response.use(
110110
const originalRequest = error.config as AxiosRequestConfig & {
111111
_retry?: boolean
112112
}
113+
const isPasswordCheckRoute = originalRequest?.url?.includes(
114+
apiRoutes.auth.passkeyUserDetails,
115+
)
113116

114117
// Automatically logout on 401
115118
if (
116119
error.response?.status === apiStatusCodes.API_STATUS_UNAUTHORIZED &&
117-
!originalRequest?._retry
120+
!originalRequest?._retry &&
121+
!isPasswordCheckRoute
118122
) {
119123
originalRequest._retry = true
120124

0 commit comments

Comments
 (0)