mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 17:31:12 -05:00
Refactor: Implement email confirmation for password auth
This commit is contained in:
@@ -213,9 +213,13 @@ export async function addPasswordToAccount(
|
||||
};
|
||||
}
|
||||
|
||||
// Step 1: Update password
|
||||
console.log('[IdentityService] Setting password for user');
|
||||
const { error: updateError } = await supabase.auth.updateUser({ password });
|
||||
// Step 1: Update password AND trigger email confirmation
|
||||
// Re-confirming the email will trigger Supabase to create the email identity
|
||||
console.log('[IdentityService] Setting password and triggering email confirmation');
|
||||
const { error: updateError } = await supabase.auth.updateUser({
|
||||
password,
|
||||
email: userEmail // Re-confirm email to create email identity provider
|
||||
});
|
||||
if (updateError) throw updateError;
|
||||
|
||||
// Step 2: Get user profile for email personalization
|
||||
@@ -248,17 +252,18 @@ export async function addPasswordToAccount(
|
||||
|
||||
// Step 4: Log the password addition
|
||||
await logIdentityChange(user!.id, 'password_added', {
|
||||
method: 'oauth_with_relogin_required'
|
||||
method: 'oauth_with_email_confirmation_required'
|
||||
});
|
||||
|
||||
// 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');
|
||||
// Step 5: Sign the user out so they can confirm email
|
||||
console.log('[IdentityService] Signing user out to complete email confirmation');
|
||||
await supabase.auth.signOut();
|
||||
|
||||
// Return success with relogin flag
|
||||
// Return success with relogin and email confirmation flags
|
||||
return {
|
||||
success: true,
|
||||
needsRelogin: true,
|
||||
needsEmailConfirmation: true,
|
||||
email: userEmail
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user