mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 01:11: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 { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
|
import { useAuth } from '@/hooks/useAuth';
|
||||||
import { Header } from '@/components/layout/Header';
|
import { Header } from '@/components/layout/Header';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
@@ -34,6 +35,15 @@ export default function Auth() {
|
|||||||
displayName: ''
|
displayName: ''
|
||||||
});
|
});
|
||||||
const defaultTab = searchParams.get('tab') || 'signin';
|
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>) => {
|
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setFormData(prev => ({
|
setFormData(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
@@ -71,8 +81,6 @@ export default function Auth() {
|
|||||||
title: "Welcome back!",
|
title: "Welcome back!",
|
||||||
description: "You've been signed in successfully."
|
description: "You've been signed in successfully."
|
||||||
});
|
});
|
||||||
const redirectTo = searchParams.get('redirect') || '/';
|
|
||||||
navigate(redirectTo);
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// Reset CAPTCHA on error
|
// Reset CAPTCHA on error
|
||||||
setSignInCaptchaToken(null);
|
setSignInCaptchaToken(null);
|
||||||
@@ -161,7 +169,6 @@ export default function Auth() {
|
|||||||
title: "Welcome to ThrillWiki!",
|
title: "Welcome to ThrillWiki!",
|
||||||
description: "Please check your email to verify your account."
|
description: "Please check your email to verify your account."
|
||||||
});
|
});
|
||||||
navigate('/');
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// Reset CAPTCHA on error
|
// Reset CAPTCHA on error
|
||||||
setCaptchaToken(null);
|
setCaptchaToken(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user