more auth fixes (logout not removing localstorage objects)

This commit is contained in:
Elizabeth Hunt 2023-04-05 01:24:48 -06:00
parent 069aeddaf9
commit 7dfea45e12
Signed by: simponic
GPG Key ID: 52B3774857EB24B1
2 changed files with 8 additions and 3 deletions

View File

@ -20,10 +20,12 @@ export default function TimerHeader({
const [modalOpen, setModalOpen] = useState<boolean>(false); const [modalOpen, setModalOpen] = useState<boolean>(false);
const [newTimerName, setNewTimerName] = useState<string>(""); const [newTimerName, setNewTimerName] = useState<string>("");
const [errors, setErrors] = useState<string[]>([]); const [errors, setErrors] = useState<string[]>([]);
const { friendName, setSignedIn } = useAuthContext(); const { friendName, setSessionOver } = useAuthContext();
const logout = () => { const logout = () => {
fetch("/api/auth/logout").then(() => setSignedIn(false)); fetch("/api/auth/logout").then(() => {
setSessionOver(new Date());
});
}; };
const createTimer = (e: any) => { const createTimer = (e: any) => {

View File

@ -79,10 +79,13 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
} }
return !!signedIn; return !!signedIn;
}); });
} else {
setSignedIn(true);
} }
return sessionOver; return sessionOver;
}); });
}, sessionOver.getTime() - Date.now()); }, Math.max(0, sessionOver.getTime() - Date.now()));
}, [sessionOver]); }, [sessionOver]);
return ( return (