{/* Password Section - Conditional based on auth method */}
@@ -282,10 +289,21 @@ export function SecurityTab() {
{showOrphanedPasswordOption && (
)}
>
diff --git a/src/lib/identityService.ts b/src/lib/identityService.ts
index 72349c3f..a861851d 100644
--- a/src/lib/identityService.ts
+++ b/src/lib/identityService.ts
@@ -290,57 +290,42 @@ export async function hasOrphanedPassword(): Promise {
}
/**
- * Re-verify password authentication by signing in and triggering email confirmation
- * This creates the missing email identity through Supabase's confirmation flow
+ * Trigger email confirmation for orphaned password
+ * Direct trigger without requiring password re-entry
*/
-export async function reverifyPasswordAuth(
- email: string,
- password: string
-): Promise {
+export async function triggerOrphanedPasswordConfirmation(): Promise {
try {
- // Step 1: Verify credentials by signing in
- console.log('[IdentityService] Verifying password credentials');
- const { data: authData, error: signInError } = await supabase.auth.signInWithPassword({
- email,
- password
- });
+ const { data: { user } } = await supabase.auth.getUser();
- if (signInError) {
+ if (!user?.email) {
return {
success: false,
- error: 'Invalid email or password'
+ error: 'No email found for current user'
};
}
- // Step 2: Trigger email confirmation to create identity
- console.log('[IdentityService] Credentials verified, triggering email confirmation');
- const { error: updateError } = await supabase.auth.updateUser({
- email: email // Re-confirming email triggers identity creation
+ console.log('[IdentityService] Triggering email confirmation for orphaned password');
+
+ const { error } = await supabase.auth.updateUser({
+ email: user.email
});
- if (updateError) throw updateError;
+ if (error) throw error;
- // Step 3: Sign out so user can confirm email
- console.log('[IdentityService] Signing out to complete email confirmation');
- await supabase.auth.signOut();
-
- // Step 4: Log the verification
- if (authData.user) {
- await logIdentityChange(authData.user.id, 'password_verified', {
- method: 'orphaned_password_recovery'
- });
- }
+ await logIdentityChange(user.id, 'orphaned_password_confirmation_triggered', {
+ method: 'manual_button_click'
+ });
return {
success: true,
needsEmailConfirmation: true,
- email
+ email: user.email
};
} catch (error: any) {
- console.error('[IdentityService] Failed to verify password:', error);
+ console.error('[IdentityService] Failed to trigger confirmation:', error);
return {
success: false,
- error: error.message || 'Failed to verify password authentication'
+ error: error.message || 'Failed to trigger email confirmation'
};
}
}