File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,8 +20,19 @@ function Home() {
2020 const { theme, profile } = useCureitContext ( ) ;
2121
2222 const navigate = useNavigate ( ) ;
23- const token = localStorage . getItem ( "sb-vakmfwtcbdeaigysjgch-auth-token" ) ;
24- const userData = token ;
23+ const [ token , setToken ] = useState ( null ) ; // ✅ state instead of direct localStorage read
24+
25+ useEffect ( ( ) => {
26+ supabase . auth . getSession ( ) . then ( ( { data : { session } } ) => {
27+ setToken ( session ?. access_token ?? null ) ; // ✅ proper session fetch
28+ } ) ;
29+
30+ const { data : { subscription } } = supabase . auth . onAuthStateChange ( ( _event , session ) => {
31+ setToken ( session ?. access_token ?? null ) ; // ✅ reacts to login/logout
32+ } ) ;
33+
34+ return ( ) => subscription . unsubscribe ( ) ; // ✅ cleanup
35+ } , [ ] ) ;
2536 const [ userInfo , setUserInfo ] = useState ( {
2637 id : "" ,
2738 name : "" ,
You can’t perform that action at this time.
0 commit comments