diff --git a/src/pages/Auth.tsx b/src/pages/Auth.tsx index f19c5368..0e6f081a 100644 --- a/src/pages/Auth.tsx +++ b/src/pages/Auth.tsx @@ -1,5 +1,6 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { useNavigate, useSearchParams } from 'react-router-dom'; +import { useAuth } from '@/hooks/useAuth'; import { Header } from '@/components/layout/Header'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; @@ -34,6 +35,15 @@ export default function Auth() { displayName: '' }); const defaultTab = searchParams.get('tab') || 'signin'; + const { user } = useAuth(); + + // Auto-redirect when user is authenticated + useEffect(() => { + if (user) { + const redirectTo = searchParams.get('redirect') || '/'; + navigate(redirectTo); + } + }, [user, navigate, searchParams]); const handleInputChange = (e: React.ChangeEvent) => { setFormData(prev => ({ ...prev, @@ -71,8 +81,6 @@ export default function Auth() { title: "Welcome back!", description: "You've been signed in successfully." }); - const redirectTo = searchParams.get('redirect') || '/'; - navigate(redirectTo); } catch (error: any) { // Reset CAPTCHA on error setSignInCaptchaToken(null); @@ -161,7 +169,6 @@ export default function Auth() { title: "Welcome to ThrillWiki!", description: "Please check your email to verify your account." }); - navigate('/'); } catch (error: any) { // Reset CAPTCHA on error setCaptchaToken(null);