mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 17:31:12 -05:00
feat: Add button to send orphaned password confirmation email
This commit is contained in:
@@ -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'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user