Merge pull request #3 from lemeow125/feature/polishlogin

Redirect back to dashboard when logging out
This commit is contained in:
lemeow125 2023-02-24 19:01:12 +08:00 committed by GitHub
commit fe463418f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,7 @@ import { useSelector, useDispatch } from "react-redux";
import { toggle } from "../../Features/Login/LoginSlice";
import { Button } from "@mui/material";
import styles from "../../styles";
import { useNavigate } from "react-router-dom";
export interface state {
logged_in: {
@ -16,16 +17,17 @@ export interface props {
export default function Logout(props: props) {
const logged_in = useSelector((state: state) => state.logged_in.value);
const dispatch = useDispatch();
const navigate = useNavigate();
async function login() {
async function logout() {
await dispatch(toggle());
await console.log("test " + logged_in);
navigate("/");
}
return (
<div style={{ paddingTop: "40vh" }}>
<Button
onClick={login}
onClick={logout}
value="Log out"
variant="contained"
style={styles.logout_button}