mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-20 06:24:07 +01:00
30 lines
692 B
JavaScript
30 lines
692 B
JavaScript
import { useEffect } from "react";
|
|
import PropTypes from "prop-types";
|
|
import { createContext, useState } from "react";
|
|
|
|
const AuthContext = createContext();
|
|
|
|
export const AuthProvider = ({ children }) => {
|
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const accessToken = localStorage.getItem("access_token");
|
|
if (accessToken) {
|
|
setIsAuthenticated(true);
|
|
}
|
|
}, []);
|
|
|
|
const contextValue = {
|
|
isAuthenticated,
|
|
setIsAuthenticated,
|
|
};
|
|
|
|
return <AuthContext.Provider value={contextValue}>{children}</AuthContext.Provider>;
|
|
};
|
|
|
|
AuthProvider.propTypes = {
|
|
children: PropTypes.node.isRequired,
|
|
};
|
|
|
|
export default AuthContext;
|