@@ -30,13 +30,17 @@ const SigninPasswordlessCodeContainer = ({
3030 integration
3131 ) ;
3232
33- const [ codeSent , setCodeSent ] = useState ( false ) ;
34- const [ sendError , setSendError ] = useState < string | null > ( null ) ;
35-
3633 const email = location . state ?. email ;
3734 const service = location . state ?. service ;
3835 const isSignup = location . state ?. isSignup ;
3936
37+ const [ codeSent , setCodeSent ] = useState (
38+ // If location state already has codeSent (persisted across page refresh
39+ // via the History API), skip sending again.
40+ ( ) => location . state ?. codeSent === true
41+ ) ;
42+ const [ sendError , setSendError ] = useState < string | null > ( null ) ;
43+
4044 const cmsInfo = integration . getCmsInfo ( ) ;
4145 // Use SigninTokenCodePage layout as fallback since SigninPasswordlessCodePage doesn't exist yet
4246 const splitLayout = ( cmsInfo as any ) ?. SigninPasswordlessCodePage ?. splitLayout ||
@@ -49,20 +53,28 @@ const SigninPasswordlessCodeContainer = ({
4953 }
5054 } , [ email , navigateWithQuery ] ) ;
5155
52- // Send the initial code when component mounts
56+ // Send the initial code when component mounts, but skip if already sent
57+ // (e.g. after a page refresh). On success, replace the current history
58+ // entry with codeSent: true so the browser-persisted location state
59+ // prevents re-sending on refresh.
5360 useEffect ( ( ) => {
5461 if ( email && ! codeSent ) {
5562 const sendCode = async ( ) => {
5663 try {
5764 await authClient . passwordlessSendCode ( email , { clientId : integration . getClientId ( ) } ) ;
5865 setCodeSent ( true ) ;
66+ // Persist codeSent in location state so it survives page refresh
67+ navigateWithQuery ( location . pathname + location . search , {
68+ replace : true ,
69+ state : { ...location . state , codeSent : true } ,
70+ } ) ;
5971 } catch ( error : any ) {
6072 setSendError ( error . message || 'Failed to send code' ) ;
6173 }
6274 } ;
6375 sendCode ( ) ;
6476 }
65- } , [ email , service , codeSent , authClient , integration ] ) ;
77+ } , [ email , service , codeSent , authClient , integration , navigateWithQuery , location . pathname , location . search , location . state ] ) ;
6678
6779 if ( ! email ) {
6880 return (
0 commit comments