use some status information to handle errors better
This commit is contained in:
		| @@ -1,7 +1,7 @@ | ||||
| import { createContext, Dispatch, SetStateAction, useEffect, useState } from 'react'; | ||||
| import { useNavigate } from 'react-router-dom'; | ||||
| import { Auth } from '../services'; | ||||
| import { IAuthState } from '../types'; | ||||
| import { BackendReturnStatus, IAuthState } from '../types'; | ||||
|  | ||||
| const InitialAuthState: IAuthState = { | ||||
|   valid: false, | ||||
| @@ -27,9 +27,9 @@ export const AuthProvider = ({ children }: { children: any }) => { | ||||
|   const resetAuth = () => setAuth(InitialAuthState); | ||||
|  | ||||
|   useEffect(() => { | ||||
|     Auth.user().then((user) => { | ||||
|       if (user !== undefined) { | ||||
|         setAuth({ valid: true, user }); | ||||
|     Auth.user().then((response) => { | ||||
|       if (response.status === BackendReturnStatus.Ok) { | ||||
|         setAuth({ valid: true, user: response.user }); | ||||
|       } else { | ||||
|         setAuth(InitialAuthState); | ||||
|       } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user