improve AUTH_TIMESTAMP clearing

This commit is contained in:
timothycarambat 2023-10-05 15:16:14 -07:00
parent f9eec86672
commit 827a29d074
6 changed files with 24 additions and 6 deletions

View File

@ -1,5 +1,5 @@
import React, { useState, createContext } from "react";
import { AUTH_TOKEN, AUTH_USER } from "./utils/constants";
import { AUTH_TIMESTAMP, AUTH_TOKEN, AUTH_USER } from "./utils/constants";
export const AuthContext = createContext(null);
export function ContextWrapper(props) {
@ -19,6 +19,7 @@ export function ContextWrapper(props) {
unsetUser: () => {
localStorage.removeItem(AUTH_USER);
localStorage.removeItem(AUTH_TOKEN);
localStorage.removeItem(AUTH_TIMESTAMP);
setStore({ user: null, authToken: null });
},
});

View File

@ -2,7 +2,11 @@ import React, { useState, useEffect } from "react";
import System from "../../../models/system";
import SingleUserAuth from "./SingleUserAuth";
import MultiUserAuth from "./MultiUserAuth";
import { AUTH_TOKEN, AUTH_USER } from "../../../utils/constants";
import {
AUTH_TIMESTAMP,
AUTH_TOKEN,
AUTH_USER,
} from "../../../utils/constants";
export default function PasswordModal({ mode = "single" }) {
return (
@ -50,6 +54,7 @@ export function usePasswordModal() {
});
window.localStorage.removeItem(AUTH_USER);
window.localStorage.removeItem(AUTH_TOKEN);
window.localStorage.removeItem(AUTH_TIMESTAMP);
return;
} else {
setAuth({

View File

@ -1,6 +1,10 @@
import React, { useState } from "react";
import System from "../../../../models/system";
import { AUTH_TOKEN, AUTH_USER } from "../../../../utils/constants";
import {
AUTH_TIMESTAMP,
AUTH_TOKEN,
AUTH_USER,
} from "../../../../utils/constants";
import paths from "../../../../utils/paths";
const noop = () => false;
@ -29,6 +33,7 @@ export default function MultiUserMode({ hideModal = noop }) {
setTimeout(() => {
window.localStorage.removeItem(AUTH_USER);
window.localStorage.removeItem(AUTH_TOKEN);
window.localStorage.removeItem(AUTH_TIMESTAMP);
window.location = paths.admin.users();
}, 2_000);
return;

View File

@ -1,6 +1,10 @@
import React, { useState } from "react";
import System from "../../../../models/system";
import { AUTH_TOKEN, AUTH_USER } from "../../../../utils/constants";
import {
AUTH_TIMESTAMP,
AUTH_TOKEN,
AUTH_USER,
} from "../../../../utils/constants";
import showToast from "../../../../utils/toast";
const noop = () => false;
@ -28,6 +32,7 @@ export default function PasswordProtection({
setTimeout(() => {
window.localStorage.removeItem(AUTH_USER);
window.localStorage.removeItem(AUTH_TOKEN);
window.localStorage.removeItem(AUTH_TIMESTAMP);
window.location.reload();
}, 3_000);
return;

View File

@ -3,7 +3,7 @@ import { Navigate } from "react-router-dom";
import { FullScreenLoader } from "../Preloader";
import validateSessionTokenForUser from "../../utils/session";
import paths from "../../utils/paths";
import { AUTH_TOKEN, AUTH_USER } from "../../utils/constants";
import { AUTH_TIMESTAMP, AUTH_TOKEN, AUTH_USER } from "../../utils/constants";
import { userFromStorage } from "../../utils/request";
import System from "../../models/system";
@ -31,6 +31,7 @@ function useIsAuthenticated() {
if (!isValid) {
localStorage.removeItem(AUTH_USER);
localStorage.removeItem(AUTH_TOKEN);
localStorage.removeItem(AUTH_TIMESTAMP);
setIsAuthed(false);
return;
}

View File

@ -21,7 +21,7 @@ import paths from "../../utils/paths";
import Discord from "../Icons/Discord";
import useUser from "../../hooks/useUser";
import { userFromStorage } from "../../utils/request";
import { AUTH_TOKEN, AUTH_USER } from "../../utils/constants";
import { AUTH_TIMESTAMP, AUTH_TOKEN, AUTH_USER } from "../../utils/constants";
import useLogo from "../../hooks/useLogo";
import SettingsOverlay, { useSystemSettingsOverlay } from "./SettingsOverlay";
@ -320,6 +320,7 @@ function LogoutButton() {
onClick={() => {
window.localStorage.removeItem(AUTH_USER);
window.localStorage.removeItem(AUTH_TOKEN);
window.localStorage.removeItem(AUTH_TIMESTAMP);
window.location.replace(paths.home());
}}
className="flex flex-grow w-[100%] h-[36px] gap-x-2 py-[5px] px-4 border border-slate-400 dark:border-transparent rounded-lg text-slate-800 dark:text-slate-200 justify-center items-center hover:bg-slate-100 dark:bg-stone-800 dark:hover:bg-stone-900"