Cleanup OAuth login

This commit is contained in:
Kieran 2022-09-08 11:00:49 +01:00
parent 3f37c10ebc
commit 3e08056f0b
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 8 additions and 4 deletions

View File

@ -3,7 +3,7 @@ import {Link} from "react-router-dom";
import {useDispatch, useSelector} from "react-redux";
import {InlineProfile} from "./InlineProfile";
import {useApi} from "./Api";
import {logout, setProfile} from "./LoginState";
import {logout, setAuth, setProfile} from "./LoginState";
import {useEffect} from "react";
import {setInfo} from "./SiteInfoStore";
@ -21,6 +21,11 @@ export function Header() {
} else {
dispatch(logout());
}
} else if(window.location.pathname === "/login" && window.location.hash.length > 1) {
dispatch(setAuth({
jwt: window.location.hash.substring(1),
profile: null
}));
}
}
async function loadStats() {
@ -33,7 +38,7 @@ export function Header() {
useEffect(() => {
initProfile();
loadStats();
}, []);
}, [jwt]);
return (
<div className="header page">

View File

@ -4,8 +4,7 @@ const LocalStorageKey = "token";
export const LoginState = createSlice({
name: "Login",
initialState: {
jwt: window.localStorage.getItem(LocalStorageKey) || (window.location.pathname === "/login" && window.location.hash.length > 1
? window.location.hash.substring(1) : null),
jwt: window.localStorage.getItem(LocalStorageKey),
profile: null
},
reducers: {