From 5e6594206035655887620f415570b213a83d812a Mon Sep 17 00:00:00 2001 From: Maulana Sodiqin Date: Sat, 29 Nov 2025 12:01:06 +0700 Subject: [PATCH] fix(auth): detect password reset tokens on login page and redirect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added useEffect to detect access_token in URL hash/query params on login page. When Supabase redirects password reset emails to /auth/login instead of /auth/callback, the page now automatically redirects to /auth/reset-password with the token. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- apps/hackathon/src/app/auth/login/page.tsx | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/hackathon/src/app/auth/login/page.tsx b/apps/hackathon/src/app/auth/login/page.tsx index ecad29a..3a1d151 100644 --- a/apps/hackathon/src/app/auth/login/page.tsx +++ b/apps/hackathon/src/app/auth/login/page.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { useGitHubAuth, useLogin, @@ -19,6 +19,26 @@ export default function LoginPage() { const [error, setError] = useState(null); const [showPassword, setShowPassword] = useState(false); + // Check for password reset tokens in URL and redirect to reset-password page + useEffect(() => { + const hashParams = new URLSearchParams(globalThis.location.hash.substring(1)); + const urlParams = new URLSearchParams(globalThis.location.search); + + const accessToken = hashParams.get('access_token') || urlParams.get('access_token'); + const type = hashParams.get('type') || urlParams.get('type'); + + // If we have an access_token, this is likely a password reset redirect that landed on the wrong page + if (accessToken) { + console.log('[Login] Detected access_token, redirecting to reset-password page'); + + // Check if it's a password recovery + if (type === 'recovery' || type === 'magiclink' || !type) { + toast.info('Redirecting to password reset...'); + navigate('/auth/reset-password?access_token=' + accessToken); + } + } + }, [navigate]); + const handleEmailLogin = async (e: React.FormEvent) => { e.preventDefault(); setError(null);