Refactor: Enhance email change status handling

This commit is contained in:
gpt-engineer-app[bot]
2025-10-01 15:45:05 +00:00
parent 04d0ff5606
commit d556243ff6
3 changed files with 37 additions and 15 deletions

View File

@@ -8,6 +8,7 @@ interface AuthContextType {
session: Session | null;
profile: Profile | null;
loading: boolean;
pendingEmail: string | null;
signOut: () => Promise<void>;
refreshProfile: () => Promise<void>;
}
@@ -19,6 +20,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
const [session, setSession] = useState<Session | null>(null);
const [profile, setProfile] = useState<Profile | null>(null);
const [loading, setLoading] = useState(true);
const [pendingEmail, setPendingEmail] = useState<string | null>(null);
const fetchProfile = async (userId: string) => {
try {
@@ -63,6 +65,10 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
setSession(session);
setUser(session?.user ?? null);
// Track pending email changes
const newEmail = session?.user?.new_email;
setPendingEmail(newEmail ?? null);
if (session?.user) {
// Defer profile fetch to avoid deadlock
setTimeout(() => {
@@ -91,6 +97,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
session,
profile,
loading,
pendingEmail,
signOut,
refreshProfile,
};