mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:51:14 -05:00
Fix: Implement orphaned password email fix
This commit is contained in:
@@ -308,15 +308,43 @@ export async function triggerOrphanedPasswordConfirmation(
|
|||||||
|
|
||||||
console.log('[IdentityService] Triggering email confirmation for orphaned password');
|
console.log('[IdentityService] Triggering email confirmation for orphaned password');
|
||||||
|
|
||||||
const { error } = await supabase.auth.updateUser({
|
// Step 1: Get user profile for email personalization
|
||||||
email: user.email
|
const { data: profile } = await supabase
|
||||||
});
|
.from('profiles')
|
||||||
|
.select('display_name, username')
|
||||||
|
.eq('user_id', user.id)
|
||||||
|
.single();
|
||||||
|
|
||||||
if (error) throw error;
|
// Step 2: Send password confirmation email via edge function
|
||||||
|
console.log('[IdentityService] Invoking send-password-added-email edge function');
|
||||||
|
const { data: emailData, error: emailError } = await supabase.functions.invoke(
|
||||||
|
'send-password-added-email',
|
||||||
|
{
|
||||||
|
body: {
|
||||||
|
email: user.email,
|
||||||
|
displayName: profile?.display_name,
|
||||||
|
username: profile?.username,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (emailError) {
|
||||||
|
console.error('[IdentityService] Edge function invocation failed:', emailError);
|
||||||
|
throw new Error(emailError.message || 'Failed to send confirmation email');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (emailData && !emailData.success) {
|
||||||
|
console.error('[IdentityService] Edge function returned error:', emailData.error);
|
||||||
|
throw new Error(emailData.error || 'Email service returned an error');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[IdentityService] Confirmation email sent successfully');
|
||||||
|
|
||||||
|
// Step 3: Log the action for audit trail
|
||||||
await logIdentityChange(user.id, 'orphaned_password_confirmation_triggered', {
|
await logIdentityChange(user.id, 'orphaned_password_confirmation_triggered', {
|
||||||
method: source || 'manual_button_click',
|
method: source || 'manual_button_click',
|
||||||
timestamp: new Date().toISOString()
|
timestamp: new Date().toISOString(),
|
||||||
|
email_sent: true
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user