Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions nextjs/src/features/passkey/PassKeyAddDevice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import * as yup from 'yup'

import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
import {
Dialog,
DialogContent,
Expand All @@ -13,6 +12,7 @@ import { Eye, EyeOff } from 'lucide-react'
import { Field, Form, Formik } from 'formik'
import { useEffect, useState } from 'react'

import { AlertComponent } from '@/components/AlertComponent'
import { AxiosResponse } from 'axios'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
Expand All @@ -39,7 +39,6 @@ export default function PasskeyAddDevice({
registerWithPasskey,
}: PasskeyAddDeviceProps): React.JSX.Element {
const [fidoUserError, setFidoUserError] = useState<string | null>(null)
const [success] = useState<string | null>(null)
const [nextStep, setNextStep] = useState(false)
const [passwordVisible, setPasswordVisible] = useState(false)
const [userEmail, setUserEmail] = useState('')
Expand All @@ -60,7 +59,7 @@ export default function PasskeyAddDevice({
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
setNextStep(true)
} else if (res.toString().includes('401')) {
setFidoUserError('Invalid Credentials')
setFidoUserError(res as string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a user-friendly error message for 401 responses rather than the raw response string. Raw output may confuse users.

Suggested change
setFidoUserError(res as string)
setFidoUserError('Unauthorized: Please log in again.')

} else {
setFidoUserError(res as string)
}
Expand All @@ -83,12 +82,17 @@ export default function PasskeyAddDevice({
<DialogTitle>Create Passkey</DialogTitle>
</DialogHeader>

{fidoUserError || success ? (
<Alert variant={fidoUserError ? 'destructive' : 'default'}>
<AlertTitle>{fidoUserError ? 'Error' : 'Success'}</AlertTitle>
<AlertDescription>{fidoUserError || success}</AlertDescription>
</Alert>
) : null}
{fidoUserError && (
<div className="w-full" role="alert">
<AlertComponent
message={fidoUserError}
type="failure"
onAlertClose={() => {
setFidoUserError(null)
}}
/>
</div>
)}

{!nextStep ? (
<Formik
Expand Down
6 changes: 5 additions & 1 deletion nextjs/src/services/axiosIntercepter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,15 @@ instance.interceptors.response.use(
const originalRequest = error.config as AxiosRequestConfig & {
_retry?: boolean
}
const isPasswordCheckRoute = originalRequest?.url?.includes(
apiRoutes.auth.passkeyUserDetails,
)

// Automatically logout on 401
if (
error.response?.status === apiStatusCodes.API_STATUS_UNAUTHORIZED &&
!originalRequest?._retry
!originalRequest?._retry &&
!isPasswordCheckRoute
) {
originalRequest._retry = true

Expand Down