mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 17:31:12 -05:00
feat: Implement password addition email notification
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user