feat: Implement password addition email notification

This commit is contained in:
gpt-engineer-app[bot]
2025-10-14 15:33:05 +00:00
parent 52cad6c4dc
commit 92a0bf1257
3 changed files with 194 additions and 2 deletions

View File

@@ -218,12 +218,40 @@ export async function addPasswordToAccount(
const { error: updateError } = await supabase.auth.updateUser({ password });
if (updateError) throw updateError;
// Step 2: Log the password addition
// Step 2: Get user profile for email personalization
console.log('[IdentityService] Fetching user profile for email');
const { data: profile } = await supabase
.from('profiles')
.select('display_name, username')
.eq('user_id', user!.id)
.single();
// Step 3: Send password addition email (before logging out)
console.log('[IdentityService] Sending password addition email');
try {
const { error: emailError } = await supabase.functions.invoke('send-password-added-email', {
body: {
email: userEmail,
displayName: profile?.display_name,
username: profile?.username,
},
});
if (emailError) {
console.error('[IdentityService] Failed to send email:', emailError);
} else {
console.log('[IdentityService] Email sent successfully');
}
} catch (emailError) {
console.error('[IdentityService] Email sending error:', emailError);
}
// Step 4: Log the password addition
await logIdentityChange(user!.id, 'password_added', {
method: 'oauth_with_relogin_required'
});
// Step 3: Sign the user out so they can sign back in with email/password
// Step 5: Sign the user out so they can sign back in with email/password
console.log('[IdentityService] Signing user out to force re-login');
await supabase.auth.signOut();