Create a context to store authentication
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import { Visibility, VisibilityOff } from "@mui/icons-material";
|
||||
import {
|
||||
Alert,
|
||||
CircularProgress,
|
||||
@ -14,11 +15,10 @@ import Grid from "@mui/material/Grid";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import * as React from "react";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
import { useAuth } from "../../App";
|
||||
import { AuthApi, PasswordLoginResult } from "../../api/AuthApi";
|
||||
import { ServerApi } from "../../api/ServerApi";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
import { VisibilityOff, Visibility } from "@mui/icons-material";
|
||||
import { useSetAtom } from "jotai";
|
||||
|
||||
/**
|
||||
* Login form
|
||||
@ -27,7 +27,7 @@ export function LoginRoute(): React.ReactElement {
|
||||
const [loading, setLoading] = React.useState(false);
|
||||
const [error, setError] = React.useState<string | null>(null);
|
||||
|
||||
const setAuth = useSetAtom(AuthApi.authStatus);
|
||||
const auth = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [mail, setMail] = React.useState("");
|
||||
@ -64,7 +64,7 @@ export function LoginRoute(): React.ReactElement {
|
||||
|
||||
case PasswordLoginResult.Success:
|
||||
navigate("/");
|
||||
setAuth(true);
|
||||
auth.setSignedIn(true);
|
||||
break;
|
||||
|
||||
case PasswordLoginResult.Error:
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { CircularProgress } from "@mui/material";
|
||||
import { useSetAtom } from "jotai";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useNavigate, useSearchParams } from "react-router-dom";
|
||||
import { AuthApi } from "../../api/AuthApi";
|
||||
import { AuthSingleMessage } from "../../widgets/AuthSingleMessage";
|
||||
import { useAuth } from "../../App";
|
||||
|
||||
/**
|
||||
* OpenID login callback route
|
||||
*/
|
||||
export function OIDCCbRoute(): React.ReactElement {
|
||||
const setAuth = useSetAtom(AuthApi.authStatus);
|
||||
const auth = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [error, setError] = useState(false);
|
||||
@ -30,7 +30,7 @@ export function OIDCCbRoute(): React.ReactElement {
|
||||
|
||||
await AuthApi.FinishOpenIDLogin(code!, state!);
|
||||
navigate("/");
|
||||
setAuth(true);
|
||||
auth.setSignedIn(true);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
setError(true);
|
||||
|
Reference in New Issue
Block a user