Fix orphaned password verification error

This commit is contained in:
gpt-engineer-app[bot]
2025-10-14 15:50:45 +00:00
parent 71991f267b
commit 1f206ceecf
3 changed files with 48 additions and 16 deletions

View File

@@ -48,9 +48,16 @@ export function PasswordVerificationDialog({
const result = await reverifyPasswordAuth(email, password); const result = await reverifyPasswordAuth(email, password);
if (result.success) { if (result.success) {
toast.success("Password Verified!", { if (result.needsEmailConfirmation) {
description: "Your password authentication has been activated.", toast.success("Password Verified!", {
}); description: "Check your email for a confirmation link to complete activation.",
duration: 8000,
});
} else {
toast.success("Password Verified!", {
description: "Your password authentication has been activated.",
});
}
onOpenChange(false); onOpenChange(false);
onSuccess(); onSuccess();
} else { } else {

View File

@@ -192,8 +192,12 @@ export function SecurityTab() {
}; };
const handleVerificationSuccess = async () => { const handleVerificationSuccess = async () => {
await loadIdentities(); // Don't reload identities immediately - user needs to confirm email first
sonnerToast.success("Password authentication activated successfully!"); toast({
title: "Email Confirmation Required",
description: "Check your email and click the confirmation link to activate password authentication.",
duration: 0, // Persistent
});
}; };
// Get connected accounts with identity data // Get connected accounts with identity data

View File

@@ -290,33 +290,54 @@ export async function hasOrphanedPassword(): Promise<boolean> {
} }
/** /**
* Re-verify password authentication by attempting sign-in * Re-verify password authentication by signing in and triggering email confirmation
* This forces Supabase to create the email identity if it's missing * This creates the missing email identity through Supabase's confirmation flow
*/ */
export async function reverifyPasswordAuth( export async function reverifyPasswordAuth(
email: string, email: string,
password: string password: string
): Promise<IdentityOperationResult> { ): Promise<IdentityOperationResult> {
try { try {
const { error } = await supabase.auth.signInWithPassword({ // Step 1: Verify credentials by signing in
console.log('[IdentityService] Verifying password credentials');
const { data: authData, error: signInError } = await supabase.auth.signInWithPassword({
email, email,
password password
}); });
if (error) throw error; if (signInError) {
// Check if email identity was created
const emailCreated = await waitForEmailProvider(3);
if (!emailCreated) {
return { return {
success: false, success: false,
error: 'Sign-in successful but identity verification failed. Please contact support.' error: 'Invalid email or password'
}; };
} }
return { success: true }; // 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
});
if (updateError) throw updateError;
// 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'
});
}
return {
success: true,
needsEmailConfirmation: true,
email
};
} catch (error: any) { } catch (error: any) {
console.error('[IdentityService] Failed to verify password:', error);
return { return {
success: false, success: false,
error: error.message || 'Failed to verify password authentication' error: error.message || 'Failed to verify password authentication'