fixed login but design is bruh

This commit is contained in:
2025-08-29 16:42:29 +03:00
parent d23546d6e0
commit 96cc825985
6 changed files with 97 additions and 23 deletions

View File

@ -4,40 +4,40 @@ import { type JSX, useEffect, useState, createContext } from "react"
type AuthContextType = {
token: string | null;
setToken: (token: string | null) => void;
loading: boolean;
};
const AuthContext = createContext<AuthContextType>({
token: null,
setToken: () => {},
loading: true,
});
export const AuthProvider = ({ children }: { children: JSX.Element }) => {
const [token, setTokenState] = useState<string | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
const savedToken = localStorage.getItem("token");
if (savedToken) {
setTokenState(savedToken);
console.log("meow")
}
console.log(savedToken)
setLoading(false)
}, []);
const setToken = (newToken: string | null) => {
setTokenState(newToken);
if (newToken) {
localStorage.setItem("token", newToken);
console.log("saved")
} else {
localStorage.removeItem("token");
console.log("removed")
}
};
return (
<AuthContext.Provider value={{ token, setToken }}>
<AuthContext.Provider value={{ token, setToken, loading }}>
{children}
</AuthContext.Provider>
);