Fix: Ensure authorization header is sent

This commit is contained in:
gpt-engineer-app[bot]
2025-10-01 16:19:57 +00:00
parent 11e6b2bf46
commit cc4da9f8ad
2 changed files with 32 additions and 6 deletions

View File

@@ -27,14 +27,23 @@ Deno.serve(async (req) => {
// Get the user from the authorization header
const authHeader = req.headers.get('Authorization');
if (!authHeader) {
throw new Error('No authorization header');
console.error('Missing authorization header');
throw new Error('No authorization header provided. Please ensure you are logged in.');
}
const token = authHeader.replace('Bearer ', '');
console.log('Attempting to verify user token...');
const { data: { user }, error: userError } = await supabaseAdmin.auth.getUser(token);
if (userError || !user) {
throw new Error('Unauthorized');
if (userError) {
console.error('Token verification failed:', userError);
throw new Error('Invalid or expired session. Please refresh the page and try again.');
}
if (!user) {
console.error('No user found for token');
throw new Error('User not found. Please refresh the page and try again.');
}
console.log(`Cancelling email change for user ${user.id}`, {