if (hash && (hash.includes('access_token') || hash.includes('error='))) {
console.log('🔄 OAuth Callback erkannt → Weiterleitung zu /password-reset.html');
return Response.redirect(`${url.origin}/password-reset.html${hash}`, 302);
}
if (pathname === '/auth/reset-password' && request.method === 'POST') {
try {
const { email } = await request.json();
if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
return new Response(JSON.stringify({ error: 'Invalid email address' }), {
status: 400,
headers: { 'Content-Type': 'application/json', ...CORS_HEADERS }
});
}
const { error } = await supabase.auth.resetPasswordForEmail(email, {
redirectTo: 'http://localhost:3000/password-reset.html'
});
if (error) {
console.error('Reset error:', error);
return new Response(JSON.stringify({ error: error.message }), {
status: 400,
headers: { 'Content-Type': 'application/json', ...CORS_HEADERS }
});
}
return new Response(JSON.stringify({ message: 'Password reset email sent' }), {
status: 200,
headers: { 'Content-Type': 'application/json', ...CORS_HEADERS }
});
} catch (error) {
console.error('Reset error:', error);
return new Response(JSON.stringify({ error: 'Failed to send reset email' }), {
status: 500,
headers: { 'Content-Type': 'application/json', ...CORS_HEADERS }
});
}
}
if (hash && (hash.includes('access_token') || hash.includes('error='))) {
console.log('🔄 OAuth Callback erkannt → Weiterleitung zu /password-reset.html');
return Response.redirect(`${url.origin}/password-reset.html${hash}`, 302);
}
if (pathname === '/auth/reset-password' && request.method === 'POST') {
try {
const { email } = await request.json();
if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
return new Response(JSON.stringify({ error: 'Invalid email address' }), {
status: 400,
headers: { 'Content-Type': 'application/json', ...CORS_HEADERS }
});
}
const { error } = await supabase.auth.resetPasswordForEmail(email, {
redirectTo: 'http://localhost:3000/password-reset.html'
});
if (error) {
console.error('Reset error:', error);
return new Response(JSON.stringify({ error: error.message }), {
status: 400,
headers: { 'Content-Type': 'application/json', ...CORS_HEADERS }
});
}
return new Response(JSON.stringify({ message: 'Password reset email sent' }), {
status: 200,
headers: { 'Content-Type': 'application/json', ...CORS_HEADERS }
});
} catch (error) {
console.error('Reset error:', error);
return new Response(JSON.stringify({ error: 'Failed to send reset email' }), {
status: 500,
headers: { 'Content-Type': 'application/json', ...CORS_HEADERS }
});
}
}