Star on GitHub
code.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { useState, useEffect } from 'react'; // Custom hook for handling user authentication state export const useAuth = () => { const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const unsubscribe = supabase.auth.onAuthStateChange((_event, session) => { setUser(session?.user ?? null); setLoading(false); }); return () => unsubscribe(); }, []); return { user, loading }; };
Undo
Redo
Center