({ children })
| 52 | } |
| 53 | |
| 54 | function 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 | |
| 83 | function useUserState() { |
| 84 | let context = React.useContext(UserStateContext); |
nothing calls this directly
no test coverage detected