MCPcopy Create free account
hub / github.com/flatlogic/react-material-admin / UserProvider

Function UserProvider

src/context/UserContext.js:54–81  ·  view source on GitHub ↗
({ children })

Source from the content-addressed store, hash-verified

52}
53
54function UserProvider({ children }) {
55 let [state, dispatch] = React.useReducer(userReducer, {
56 isAuthenticated: () => {
57 const token = localStorage.getItem('token');
58 if (config.isBackend && token) {
59 const date = new Date().getTime() / 1000;
60 const data = decodeJwtPayload(token);
61 if (!data) return false;
62 return date < data.exp;
63 } else if (token) {
64 return true;
65 }
66 return false;
67 },
68 isFetching: false,
69 errorMessage: '',
70 currentUser: null,
71 loadingInit: true,
72 });
73
74 return (
75 <UserStateContext.Provider value={state}>
76 <UserDispatchContext.Provider value={dispatch}>
77 {children}
78 </UserDispatchContext.Provider>
79 </UserStateContext.Provider>
80 );
81}
82
83function useUserState() {
84 let context = React.useContext(UserStateContext);

Callers

nothing calls this directly

Calls 1

decodeJwtPayloadFunction · 0.90

Tested by

no test coverage detected