main
Last change
on this file was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago |
Pred finalna verzija
|
-
Property mode
set to
100644
|
File size:
880 bytes
|
Rev | Line | |
---|
[0c6b92a] | 1 | import React, {createContext, useState, useContext, useEffect} from 'react';
|
---|
| 2 | import {verifyToken} from "../../scripts/util/verifyToken.js";
|
---|
| 3 |
|
---|
| 4 | const AppContext = createContext();
|
---|
| 5 | export const AppProvider = ({ children }) => {
|
---|
| 6 | const [isAuthenticated, setIsAuthenticated] = useState(false);
|
---|
| 7 | const [username, setUsername] = useState('');
|
---|
| 8 | const [loading, setLoading] = useState(true);
|
---|
| 9 |
|
---|
| 10 | useEffect(() => {
|
---|
| 11 | verifyToken(setIsAuthenticated,setUsername,setLoading)
|
---|
| 12 | }, []);
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | return (
|
---|
| 16 | <AppContext.Provider
|
---|
| 17 | value={{
|
---|
| 18 | isAuthenticated,
|
---|
| 19 | username,
|
---|
| 20 | loading,
|
---|
| 21 | setIsAuthenticated,
|
---|
| 22 | setUsername,
|
---|
| 23 | setLoading,
|
---|
| 24 | }}
|
---|
| 25 | >
|
---|
| 26 | {children}
|
---|
| 27 | </AppContext.Provider>
|
---|
| 28 | );
|
---|
| 29 | };
|
---|
| 30 |
|
---|
| 31 | export const useAppContext = () => useContext(AppContext);
|
---|
Note:
See
TracBrowser
for help on using the repository browser.