Improve auth flow error handling and add debug logging

- Add early returns for better error handling flow
- Add console.log for SignUp result to debug user creation
- Ensure loading state is always reset properly
- Add explicit check for missing user data after signUp
This commit is contained in:
dwindown
2026-01-02 14:34:09 +07:00
parent 06d6845456
commit 079c0f947c

View File

@@ -69,6 +69,9 @@ export default function Auth() {
} }
const { error, data } = await signUp(email, password, name); const { error, data } = await signUp(email, password, name);
console.log('SignUp result:', { error, data, hasUser: !!data?.user, hasSession: !!data?.session });
if (error) { if (error) {
if (error.message.includes('already registered')) { if (error.message.includes('already registered')) {
toast({ title: 'Error', description: 'This email is already registered. Please login instead.', variant: 'destructive' }); toast({ title: 'Error', description: 'This email is already registered. Please login instead.', variant: 'destructive' });
@@ -76,7 +79,15 @@ export default function Auth() {
toast({ title: 'Error', description: error.message, variant: 'destructive' }); toast({ title: 'Error', description: error.message, variant: 'destructive' });
} }
setLoading(false); setLoading(false);
} else if (data?.user) { return;
}
if (!data?.user) {
toast({ title: 'Error', description: 'Failed to create user account. Please try again.', variant: 'destructive' });
setLoading(false);
return;
}
// User created, now send OTP // User created, now send OTP
const userId = data.user.id; const userId = data.user.id;
console.log('User created successfully:', { userId, email, session: data.session }); console.log('User created successfully:', { userId, email, session: data.session });
@@ -98,7 +109,6 @@ export default function Auth() {
} }
setLoading(false); setLoading(false);
} }
}
}; };
const handleOTPSubmit = async (e: React.FormEvent) => { const handleOTPSubmit = async (e: React.FormEvent) => {