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 {useDispatch, useSelector} from "react-redux";
import {InlineProfile} from "./InlineProfile"; import {InlineProfile} from "./InlineProfile";
import {useApi} from "./Api"; import {useApi} from "./Api";
import {logout, setProfile} from "./LoginState"; import {logout, setAuth, setProfile} from "./LoginState";
import {useEffect} from "react"; import {useEffect} from "react";
import {setInfo} from "./SiteInfoStore"; import {setInfo} from "./SiteInfoStore";
@ -21,6 +21,11 @@ export function Header() {
} else { } else {
dispatch(logout()); 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() { async function loadStats() {
@ -33,7 +38,7 @@ export function Header() {
useEffect(() => { useEffect(() => {
initProfile(); initProfile();
loadStats(); loadStats();
}, []); }, [jwt]);
return ( return (
<div className="header page"> <div className="header page">

View File

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