@@ -11,14 +11,14 @@ import {
1111} from '@/components/ui/dialog'
1212import { Eye , EyeOff } from 'lucide-react'
1313import { Field , Form , Formik } from 'formik'
14+ import { useEffect , useState } from 'react'
1415
1516import { AxiosResponse } from 'axios'
1617import { Button } from '@/components/ui/button'
1718import { Input } from '@/components/ui/input'
1819import { addPasskeyUserDetails } from '@/app/api/Fido'
1920import { apiStatusCodes } from '@/config/CommonConstant'
2021import { passwordEncryption } from '@/app/api/Auth'
21- import { useState } from 'react'
2222
2323interface PasswordValue {
2424 Password : string
@@ -29,7 +29,7 @@ interface PasskeyAddDeviceProps {
2929 setOpenModel : ( flag : boolean ) => void
3030 closeModal : ( flag : boolean ) => void
3131 registerWithPasskey : ( flag : boolean ) => Promise < void >
32- email : string | undefined
32+ email : string | null
3333}
3434
3535export default function PasskeyAddDevice ( {
@@ -42,10 +42,15 @@ export default function PasskeyAddDevice({
4242 const [ success ] = useState < string | null > ( null )
4343 const [ nextStep , setNextStep ] = useState ( false )
4444 const [ passwordVisible , setPasswordVisible ] = useState ( false )
45+ const [ userEmail , setUserEmail ] = useState ( '' )
4546
46- const userEmail = email
4747 const savePassword = async ( values : PasswordValue ) : Promise < void > => {
4848 try {
49+ if ( ! userEmail ) {
50+ setFidoUserError ( 'User email is missing. Please refresh the page.' )
51+ return
52+ }
53+
4954 const payload = {
5055 password : passwordEncryption ( values . Password ) ,
5156 }
@@ -65,6 +70,12 @@ export default function PasskeyAddDevice({
6570 }
6671 }
6772
73+ useEffect ( ( ) => {
74+ if ( email ) {
75+ setUserEmail ( email )
76+ }
77+ } , [ email ] )
78+
6879 return (
6980 < Dialog open = { openModal } onOpenChange = { setOpenModel } >
7081 < DialogContent >
0 commit comments