mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 07:11:11 -05:00
Fix: Deduplicate toast and add session dismissal
This commit is contained in:
@@ -34,6 +34,7 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
||||
// Refs for lifecycle and cleanup management
|
||||
const novuUpdateTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const previousEmailRef = useRef<string | null>(null);
|
||||
const orphanedPasswordToastShownRef = useRef(false);
|
||||
|
||||
// Verify session is still valid - simplified
|
||||
const verifySession = async () => {
|
||||
@@ -98,6 +99,7 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
||||
setUser(null);
|
||||
setAal(null);
|
||||
setLoading(false);
|
||||
orphanedPasswordToastShownRef.current = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -115,6 +117,16 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
||||
// 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');
|
||||
@@ -128,12 +140,15 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
||||
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: "Your password needs email confirmation to be fully activated.",
|
||||
duration: Infinity, // Persistent until dismissed
|
||||
duration: Infinity,
|
||||
action: {
|
||||
label: "Resend Email",
|
||||
onClick: async () => {
|
||||
@@ -154,7 +169,10 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
||||
},
|
||||
cancel: {
|
||||
label: "Dismiss",
|
||||
onClick: () => {} // Allow dismissal
|
||||
onClick: () => {
|
||||
setOrphanedPasswordDismissed();
|
||||
authLog('[Auth] User dismissed orphaned password warning');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user