._.
This commit is contained in:
parent
63a92422fd
commit
e345488763
@ -1,3 +1,11 @@
|
|||||||
|
import React, { createContext, useContext, useState, useEffect } from 'react';
|
||||||
|
|
||||||
|
const AuthContext = createContext();
|
||||||
|
|
||||||
|
export const useAuth = () => {
|
||||||
|
return useContext(AuthContext);
|
||||||
|
};
|
||||||
|
|
||||||
export const AuthProvider = ({ children }) => {
|
export const AuthProvider = ({ children }) => {
|
||||||
const [isAuthenticated, setIsAuthenticated] = useState(() => {
|
const [isAuthenticated, setIsAuthenticated] = useState(() => {
|
||||||
const savedAuth = localStorage.getItem('isAuthenticated');
|
const savedAuth = localStorage.getItem('isAuthenticated');
|
||||||
|
|||||||
@ -5,6 +5,10 @@ import { useAuth } from '../AuthContext.jsx';
|
|||||||
const PrivateRoute = () => {
|
const PrivateRoute = () => {
|
||||||
const { isAuthenticated } = useAuth();
|
const { isAuthenticated } = useAuth();
|
||||||
|
|
||||||
|
if (isAuthenticated === null) {
|
||||||
|
return <div>Loading...</div>;
|
||||||
|
}
|
||||||
|
|
||||||
return isAuthenticated ? <Outlet /> : <Navigate to="/login" />;
|
return isAuthenticated ? <Outlet /> : <Navigate to="/login" />;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -2,5 +2,9 @@ import React, { useState, useEffect } from 'react';
|
|||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
|
|
||||||
return
|
return (
|
||||||
|
<div>
|
||||||
|
sadvsgrhgrtshte
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user