mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 08:11:13 -05:00
Fix: Prevent logout on email change cancellation
This commit is contained in:
@@ -34,7 +34,7 @@ const profileSchema = z.object({
|
|||||||
type ProfileFormData = z.infer<typeof profileSchema>;
|
type ProfileFormData = z.infer<typeof profileSchema>;
|
||||||
|
|
||||||
export function AccountProfileTab() {
|
export function AccountProfileTab() {
|
||||||
const { user, profile, refreshProfile, pendingEmail } = useAuth();
|
const { user, profile, refreshProfile, pendingEmail, clearPendingEmail } = useAuth();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [avatarLoading, setAvatarLoading] = useState(false);
|
const [avatarLoading, setAvatarLoading] = useState(false);
|
||||||
@@ -173,11 +173,8 @@ export function AccountProfileTab() {
|
|||||||
throw new Error(data?.error || 'Failed to cancel email change');
|
throw new Error(data?.error || 'Failed to cancel email change');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force refresh the session to get updated user state
|
// Clear the pending email state immediately without refreshing session
|
||||||
const { error: refreshError } = await supabase.auth.refreshSession();
|
clearPendingEmail();
|
||||||
if (refreshError) {
|
|
||||||
console.error('Session refresh error:', refreshError);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update Novu subscriber back to current email
|
// Update Novu subscriber back to current email
|
||||||
if (notificationService.isEnabled()) {
|
if (notificationService.isEnabled()) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ interface AuthContextType {
|
|||||||
pendingEmail: string | null;
|
pendingEmail: string | null;
|
||||||
signOut: () => Promise<void>;
|
signOut: () => Promise<void>;
|
||||||
refreshProfile: () => Promise<void>;
|
refreshProfile: () => Promise<void>;
|
||||||
|
clearPendingEmail: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||||
@@ -152,6 +153,10 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const clearPendingEmail = () => {
|
||||||
|
setPendingEmail(null);
|
||||||
|
};
|
||||||
|
|
||||||
const value = {
|
const value = {
|
||||||
user,
|
user,
|
||||||
session,
|
session,
|
||||||
@@ -160,6 +165,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|||||||
pendingEmail,
|
pendingEmail,
|
||||||
signOut,
|
signOut,
|
||||||
refreshProfile,
|
refreshProfile,
|
||||||
|
clearPendingEmail,
|
||||||
};
|
};
|
||||||
|
|
||||||
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
||||||
|
|||||||
Reference in New Issue
Block a user