Add debug logging for OTP auth flow

This commit is contained in:
dwindown
2026-01-02 13:52:28 +07:00
parent c6250d2b47
commit 219ad11202
2 changed files with 235 additions and 61 deletions

View File

@@ -107,20 +107,35 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const sendAuthOTP = async (userId: string, email: string) => {
try {
const { data: { session } } = await supabase.auth.getSession();
const token = session?.access_token || import.meta.env.VITE_SUPABASE_ANON_KEY;
console.log('Sending OTP request', { userId, email, hasSession: !!session });
const response = await fetch(
`${import.meta.env.VITE_SUPABASE_URL}/functions/v1/send-auth-otp`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${session?.access_token || import.meta.env.VITE_SUPABASE_ANON_KEY}`,
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ user_id: userId, email }),
}
);
console.log('OTP response status:', response.status);
if (!response.ok) {
const errorText = await response.text();
console.error('OTP request failed:', response.status, errorText);
return {
success: false,
message: `HTTP ${response.status}: ${errorText}`
};
}
const result = await response.json();
console.log('OTP result:', result);
return result;
} catch (error: any) {
console.error('Error sending OTP:', error);