Refactor identity management

This commit is contained in:
gpt-engineer-app[bot]
2025-10-14 17:38:18 +00:00
parent 5c075c363e
commit a255442616
5 changed files with 21 additions and 456 deletions

View File

@@ -113,74 +113,6 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
} else {
setAal(null);
}
// Check for orphaned password on SIGNED_IN events
if (event === 'SIGNED_IN' && session?.user) {
try {
// Import sessionFlags
const { isOrphanedPasswordDismissed, setOrphanedPasswordDismissed } =
await import('@/lib/sessionFlags');
// Skip if already shown in this auth cycle or dismissed this session
if (orphanedPasswordToastShownRef.current || isOrphanedPasswordDismissed()) {
authLog('[Auth] Skipping orphaned password toast - already shown or dismissed');
return;
}
// Import identityService functions
const { getUserIdentities, hasOrphanedPassword, triggerOrphanedPasswordConfirmation } =
await import('@/lib/identityService');
// Check if user has email identity
const identities = await getUserIdentities();
const hasEmailIdentity = identities.some(i => i.provider === 'email');
// If no email identity but has other identities, check for orphaned password
if (!hasEmailIdentity && identities.length > 0) {
const isOrphaned = await hasOrphanedPassword();
if (isOrphaned) {
// Mark as shown to prevent duplicates
orphanedPasswordToastShownRef.current = true;
// Show persistent toast with Resend button
const { toast: sonnerToast } = await import('sonner');
sonnerToast.warning("Password Activation Pending", {
description: "Check your email for a password reset link to complete activation. You'll receive two emails: one from Supabase with the reset link, and one from ThrillWiki with instructions.",
duration: Infinity,
action: {
label: "Resend Email",
onClick: async () => {
const result = await triggerOrphanedPasswordConfirmation('signin_toast');
if (result.success) {
sonnerToast.success("Reset Email Sent!", {
description: `Check ${result.email} for the password reset link from Supabase.`,
duration: 10000,
});
} else {
sonnerToast.error("Failed to Send Email", {
description: result.error,
duration: 8000,
});
}
}
},
cancel: {
label: "Dismiss",
onClick: () => {
setOrphanedPasswordDismissed();
authLog('[Auth] User dismissed orphaned password warning');
}
}
});
}
}
} catch (error) {
authError('[Auth] Failed to check for orphaned password:', error);
}
}
}, 0);
// Detect confirmed email change: email changed AND no longer pending