mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 18:31:13 -05:00
Fix: Implement auth page auto-redirect
This commit is contained in:
@@ -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<HTMLInputElement>) => {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user