Fix: Prevent logout on email change cancellation

This commit is contained in:
gpt-engineer-app[bot]
2025-10-01 16:39:52 +00:00
parent 882d06b70f
commit c00f991b1e
2 changed files with 9 additions and 6 deletions

View File

@@ -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()) {

View File

@@ -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>;