feat: Add button to send orphaned password confirmation email

This commit is contained in:
gpt-engineer-app[bot]
2025-10-14 15:57:53 +00:00
parent 1f206ceecf
commit 4ce2c266eb
3 changed files with 58 additions and 214 deletions

View File

@@ -290,57 +290,42 @@ export async function hasOrphanedPassword(): Promise<boolean> {
}
/**
* 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<IdentityOperationResult> {
export async function triggerOrphanedPasswordConfirmation(): Promise<IdentityOperationResult> {
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'
};
}
}