@@ -10,25 +10,31 @@ export default function ResetPassword() {
1010 const [ error , setError ] = useState ( null ) ;
1111 const [ success , setSuccess ] = useState ( false ) ;
1212 const [ isOAuthAccount , setIsOAuthAccount ] = useState ( false ) ;
13+ const [ isRecoverySession , setIsRecoverySession ] = useState ( false ) ;
1314 const [ showPassword , setShowPassword ] = useState ( false ) ;
1415 const [ showConfirmPassword , setShowConfirmPassword ] = useState ( false ) ;
1516 const navigate = useNavigate ( ) ;
1617
1718 useEffect ( ( ) => {
1819 // Check if this is an OAuth-only account (no password set yet)
1920 const checkAuthProvider = async ( ) => {
20- // Parse URL hash for Supabase auth parameters
21+ // Check sessionStorage for recovery flag (set by App.jsx when hash was detected)
22+ const recoveryActive = sessionStorage . getItem ( 'password_recovery_active' ) === 'true' ;
23+
24+ // Also check URL hash as fallback (in case user navigated directly)
2125 const hashParams = new URLSearchParams ( window . location . hash . substring ( 1 ) ) ;
2226 const tokenType = hashParams . get ( 'type' ) ;
2327 const accessToken = hashParams . get ( 'access_token' ) ;
2428
29+ console . log ( 'Recovery active from sessionStorage:' , recoveryActive ) ;
2530 console . log ( 'URL hash type:' , tokenType ) ;
2631 console . log ( 'Has access token:' , ! ! accessToken ) ;
2732
28- // If coming from password reset email (has type= recovery in hash)
33+ // If coming from password reset email (recovery flag set or hash present )
2934 // ALWAYS show password reset form, never redirect
30- if ( tokenType === 'recovery' || accessToken ) {
35+ if ( recoveryActive || tokenType === 'recovery' || accessToken ) {
3136 console . log ( 'Password reset link detected - showing reset form' ) ;
37+ setIsRecoverySession ( true ) ;
3238 setIsOAuthAccount ( false ) ;
3339 return ;
3440 }
@@ -79,17 +85,16 @@ export default function ResetPassword() {
7985 setError ( updateError . message ) ;
8086 setLoading ( false ) ;
8187 } else {
82- // Check again if this was a password reset (recovery) session
83- const hashParams = new URLSearchParams ( window . location . hash . substring ( 1 ) ) ;
84- const wasRecoverySession = hashParams . get ( 'type' ) === 'recovery' ;
85-
8688 console . log ( 'Password updated successfully' ) ;
87- console . log ( 'Was recovery session:' , wasRecoverySession ) ;
89+ console . log ( 'Was recovery session:' , isRecoverySession ) ;
8890 console . log ( 'Is OAuth account:' , isOAuthAccount ) ;
8991
9092 // If they came from a password reset link, sign them out regardless of OAuth
91- if ( wasRecoverySession ) {
93+ if ( isRecoverySession ) {
9294 console . log ( 'Recovery session - signing out user' ) ;
95+ // Clear the URL hash and recovery flag to prevent recovery loop
96+ window . history . replaceState ( null , '' , window . location . pathname ) ;
97+ sessionStorage . removeItem ( 'password_recovery_active' ) ;
9398 await supabase . auth . signOut ( ) ;
9499 setSuccess ( true ) ;
95100 } else if ( isOAuthAccount ) {
0 commit comments