forked from Kieran/void.cat
Cleanup OAuth login
This commit is contained in:
parent
3f37c10ebc
commit
3e08056f0b
@ -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">
|
||||||
|
@ -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: {
|
||||||
|
Loading…
Reference in New Issue
Block a user