mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 07:11:11 -05:00
Refactor: Enhance email change status handling
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user