use some status information to handle errors better

This commit is contained in:
Sven Czarnian
2022-11-05 00:10:27 +01:00
parent 47c09f2fdd
commit df0a6ade57
6 changed files with 107 additions and 24 deletions

View File

@@ -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);
}