Skip to content

Commit ae5b908

Browse files
Replace direct localStorage read with state management
Refactor token handling to use state and session management.
1 parent 8bbb4c4 commit ae5b908

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

frontend/src/pages/Home.jsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff 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: "",

0 commit comments

Comments
 (0)