mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 16:51:13 -05:00
Fix: Implement complete fix
This commit is contained in:
@@ -14,6 +14,7 @@ import { supabase } from '@/integrations/supabase/client';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { TurnstileCaptcha } from '@/components/auth/TurnstileCaptcha';
|
||||
import { notificationService } from '@/lib/notificationService';
|
||||
import { StorageWarning } from '@/components/auth/StorageWarning';
|
||||
export default function Auth() {
|
||||
const [searchParams] = useSearchParams();
|
||||
const navigate = useNavigate();
|
||||
@@ -70,6 +71,11 @@ export default function Auth() {
|
||||
setSignInCaptchaToken(null);
|
||||
|
||||
try {
|
||||
console.log('[Auth] Attempting sign in...', {
|
||||
email: formData.email,
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const {
|
||||
data,
|
||||
error
|
||||
@@ -80,19 +86,54 @@ export default function Auth() {
|
||||
captchaToken: tokenToUse
|
||||
}
|
||||
});
|
||||
|
||||
if (error) throw error;
|
||||
toast({
|
||||
title: "Welcome back!",
|
||||
description: "You've been signed in successfully."
|
||||
|
||||
console.log('[Auth] Sign in successful', {
|
||||
user: data.user?.email,
|
||||
session: !!data.session,
|
||||
sessionExpiry: data.session?.expires_at
|
||||
});
|
||||
|
||||
// Verify session was stored
|
||||
setTimeout(async () => {
|
||||
const { data: { session } } = await supabase.auth.getSession();
|
||||
if (!session) {
|
||||
console.error('[Auth] Session not found after login!');
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "Session Error",
|
||||
description: "Login succeeded but session was not stored. Please check your browser settings and enable cookies/storage."
|
||||
});
|
||||
} else {
|
||||
console.log('[Auth] Session verified after login');
|
||||
toast({
|
||||
title: "Welcome back!",
|
||||
description: "You've been signed in successfully."
|
||||
});
|
||||
}
|
||||
}, 500);
|
||||
|
||||
} catch (error: any) {
|
||||
// Reset CAPTCHA widget to force fresh token generation
|
||||
setSignInCaptchaKey(prev => prev + 1);
|
||||
|
||||
console.error('[Auth] Sign in error:', error);
|
||||
|
||||
// Enhanced error messages
|
||||
let errorMessage = error.message;
|
||||
if (error.message.includes('Invalid login credentials')) {
|
||||
errorMessage = 'Invalid email or password. Please try again.';
|
||||
} else if (error.message.includes('Email not confirmed')) {
|
||||
errorMessage = 'Please confirm your email address before signing in.';
|
||||
} else if (error.message.includes('Too many requests')) {
|
||||
errorMessage = 'Too many login attempts. Please wait a few minutes and try again.';
|
||||
}
|
||||
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "Sign in failed",
|
||||
description: error.message
|
||||
description: errorMessage
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -251,6 +292,7 @@ export default function Auth() {
|
||||
|
||||
<main className="container mx-auto px-4 py-16">
|
||||
<div className="max-w-md mx-auto">
|
||||
<StorageWarning />
|
||||
<div className="text-center mb-8">
|
||||
<div className="flex items-center justify-center gap-2 mb-4">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user