Create a context to store authentication

This commit is contained in:
2023-06-15 08:45:21 +02:00
parent 10e5c124fd
commit 1934354665
10 changed files with 71 additions and 92 deletions

View File

@ -7,9 +7,9 @@ import Menu from "@mui/material/Menu";
import MenuItem from "@mui/material/MenuItem";
import Toolbar from "@mui/material/Toolbar";
import Typography from "@mui/material/Typography";
import { useSetAtom } from "jotai";
import * as React from "react";
import { Link, Outlet, useNavigate } from "react-router-dom";
import { useAuth } from "../App";
import { AuthApi } from "../api/AuthApi";
import { User, UserApi } from "../api/UserApi";
import { AsyncWidget } from "./AsyncWidget";
@ -18,7 +18,7 @@ import { RouterLink } from "./RouterLink";
export function BaseAuthenticatedPage(): React.ReactElement {
const [user, setUser] = React.useState<null | User>(null);
const setSignedIn = useSetAtom(AuthApi.authStatus);
const auth = useAuth();
const navigate = useNavigate();
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
@ -39,7 +39,7 @@ export function BaseAuthenticatedPage(): React.ReactElement {
handleCloseMenu();
AuthApi.SignOut();
navigate("/");
setSignedIn(false);
auth.setSignedIn(false);
};
return (