{"version":3,"file":"EmailCallback-CtKcybXp.js","sources":["../../../app/javascript/entrypoints/EmailCallback/EmailCallback.jsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport { useLocation, useNavigate } from 'react-router-dom';\nimport { getAuth, applyActionCode, sendEmailVerification, signOut, checkActionCode } from 'firebase/auth';\nimport { Box, Typography, Button, CircularProgress } from '@mui/material';\nimport ContainerBox from '../../shared/ContainerBox';\n\nconst EmailCallback = () => {\n const location = useLocation();\n const navigate = useNavigate();\n const [newEmail, setNewEmail] = useState('');\n const [verificationStatus, setVerificationStatus] = useState('verifying');\n const [errorMessage, setErrorMessage] = useState('');\n const [resendDisabled, setResendDisabled] = useState(false);\n\n useEffect(() => {\n const doEmailCallback = async () => {\n const auth = getAuth();\n const params = new URLSearchParams(location.search);\n const actionCode = params.get('oobCode');\n const mode = params.get('mode');\n\n console.log('actionCode:', actionCode);\n console.log('mode:', mode);\n\n if (!actionCode || (mode !== 'verifyEmail' && mode !== 'verifyAndChangeEmail')) {\n setVerificationStatus('manual');\n return;\n }\n\n try {\n // Verify the action code is valid\n await checkActionCode(auth, actionCode);\n\n // Apply the action code\n await applyActionCode(auth, actionCode);\n setVerificationStatus('success');\n } catch (error) {\n console.error('Error applying action code:', error);\n setErrorMessage('The action code is invalid or has expired. Please request a new verification email.');\n setVerificationStatus('error');\n return; // Exit early if applyActionCode fails\n }\n\n // Optionally, you can attempt to reload the user\n const user = auth.currentUser;\n if (user) {\n try {\n await user.reload();\n setNewEmail(user.email);\n } catch (error) {\n console.error('Error reloading user:', error);\n if (error.code === 'auth/user-token-expired') {\n setErrorMessage('Your session has expired. Please sign in again.');\n }\n }\n }\n };\n\n doEmailCallback();\n }, [location]);\n\n const handleSignOut = async () => {\n const auth = getAuth();\n try {\n await signOut(auth);\n navigate('/login');\n } catch (error) {\n console.error('Error signing out:', error);\n setErrorMessage('Failed to sign out. Please try again.');\n }\n };\n\n const resendVerificationEmail = async () => {\n const auth = getAuth();\n const user = auth.currentUser;\n if (user) {\n try {\n await sendEmailVerification(user);\n setResendDisabled(true);\n setTimeout(() => setResendDisabled(false), 60000); // Disable for 1 minute\n alert('A new verification email has been sent. Please check your inbox.');\n } catch (error) {\n console.error('Error sending verification email:', error);\n alert('Failed to send verification email. Please try again later.');\n }\n } else {\n alert('No user is currently signed in. Please sign in and try again.');\n }\n };\n\n return (\n \n {verificationStatus === 'verifying' ? (\n \n \n \n ) : verificationStatus === 'manual' ? (\n \n Please check your email for a verification link.\n \n Resend Verification Email\n \n navigate('/dashboard')}\n sx={{ mt: 2 }}\n >\n Go to the Dashboard\n \n \n ) : verificationStatus && (\n \n Email verified successfully!\n navigate('/dashboard')}\n sx={{ mt: 2 }}\n >\n Go to the Dashboard\n \n \n )}\n \n );\n};\n\nexport default EmailCallback;\n"],"names":["EmailCallback","location","useLocation","navigate","useNavigate","newEmail","setNewEmail","useState","verificationStatus","setVerificationStatus","errorMessage","setErrorMessage","resendDisabled","setResendDisabled","useEffect","auth","getAuth","params","actionCode","mode","checkActionCode","applyActionCode","error","user","resendVerificationEmail","sendEmailVerification","ContainerBox","React","Box","CircularProgress","Typography","Button"],"mappings":"8qBAMA,MAAMA,EAAgB,IAAM,CAC1B,MAAMC,EAAWC,IACXC,EAAWC,IACX,CAACC,EAAUC,CAAW,EAAIC,WAAS,EAAE,EACrC,CAACC,EAAoBC,CAAqB,EAAIF,WAAS,WAAW,EAClE,CAACG,EAAcC,CAAe,EAAIJ,WAAS,EAAE,EAC7C,CAACK,EAAgBC,CAAiB,EAAIN,WAAS,EAAK,EAE1DO,EAAAA,UAAU,IAAM,EACU,SAAY,CAClC,MAAMC,EAAOC,IACPC,EAAS,IAAI,gBAAgBhB,EAAS,MAAM,EAC5CiB,EAAaD,EAAO,IAAI,SAAS,EACjCE,EAAOF,EAAO,IAAI,MAAM,EAK9B,GAHQ,QAAA,IAAI,cAAeC,CAAU,EAC7B,QAAA,IAAI,QAASC,CAAI,EAErB,CAACD,GAAeC,IAAS,eAAiBA,IA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