mirror of
https://github.com/Unkn0wnCat/matrix-veles.git
synced 2025-06-24 13:27:16 +02:00
webui: Add logout functionality
This commit is contained in:
parent
b4aa9caff4
commit
45ca353b3f
2 changed files with 13 additions and 8 deletions
|
@ -6,7 +6,7 @@ import RegisterView from "./components/auth/RegisterView";
|
|||
import RequireAuth from "./features/auth/RequireAuth";
|
||||
import {useAppDispatch} from "./app/hooks";
|
||||
import broadcastChannel from "./app/broadcastChannel";
|
||||
import {receiveAuthUpdate} from "./features/auth/authSlice";
|
||||
import {logOut, receiveAuthUpdate} from "./features/auth/authSlice";
|
||||
|
||||
function App() {
|
||||
const dispatch = useAppDispatch()
|
||||
|
@ -23,7 +23,10 @@ function App() {
|
|||
<Route path={"login"} element={<LoginView/>} />
|
||||
<Route path={"register"} element={<RegisterView/>} />
|
||||
</Route>
|
||||
<Route path={"/"} element={<RequireAuth><h1>hi</h1></RequireAuth>}/>
|
||||
<Route path={"/"} element={<RequireAuth><h1>hi</h1> <button onClick={() => {
|
||||
dispatch(logOut())
|
||||
}
|
||||
}>Log out</button></RequireAuth>}/>
|
||||
</Routes>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React from "react";
|
||||
import React, {useEffect} from "react";
|
||||
|
||||
import styles from "./AuthLayout.module.scss";
|
||||
import {Link, useLocation, useNavigate, useOutlet} from "react-router-dom";
|
||||
|
@ -23,12 +23,14 @@ const AuthLayout = () => {
|
|||
const navigate = useNavigate()
|
||||
|
||||
|
||||
if(authState.status == "logged_in") {
|
||||
if(locationState && locationState.location) {
|
||||
navigate(locationState.location, {replace: true})
|
||||
useEffect(() => {
|
||||
if(authState.status == "logged_in") {
|
||||
if(locationState && locationState.location) {
|
||||
navigate(locationState.location, {replace: true})
|
||||
}
|
||||
navigate("/", {replace: true})
|
||||
}
|
||||
navigate("/", {replace: true})
|
||||
}
|
||||
}, [authState])
|
||||
|
||||
return <div className={styles.auth}>
|
||||
<div className={styles.background}/>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue