Refactor: Implement email confirmation for password auth

This commit is contained in:
gpt-engineer-app[bot]
2025-10-14 15:39:05 +00:00
parent 92a0bf1257
commit 677f14ee7b
6 changed files with 49 additions and 26 deletions

View File

@@ -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
};