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