mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
**Related issue:** Resolves #14401 this updates the mechanism of storing the auth token for a user that is used for making requests and validating a user session. We change the storage from local storage to a cookie. This allow a bit more security and prepares for a future change where we will allow the browser to handle setting and passing the auth token in the request. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. - [x] QA'd all new/changed functionality manually
40 lines
1 KiB
TypeScript
40 lines
1 KiB
TypeScript
import { useContext, useEffect } from "react";
|
|
import { InjectedRouter } from "react-router";
|
|
|
|
import { AppContext } from "context/app";
|
|
import { NotificationContext } from "context/notification";
|
|
import sessionsAPI from "services/entities/sessions";
|
|
import authToken from "utilities/auth_token";
|
|
|
|
interface ILogoutPageProps {
|
|
router: InjectedRouter;
|
|
}
|
|
|
|
const LogoutPage = ({ router }: ILogoutPageProps) => {
|
|
const { isSandboxMode } = useContext(AppContext);
|
|
const { renderFlash } = useContext(NotificationContext);
|
|
|
|
useEffect(() => {
|
|
const logoutUser = async () => {
|
|
try {
|
|
await sessionsAPI.destroy();
|
|
authToken.remove();
|
|
setTimeout(() => {
|
|
window.location.href = isSandboxMode
|
|
? "https://www.fleetdm.com/logout"
|
|
: "/";
|
|
}, 500);
|
|
} catch (response) {
|
|
console.error(response);
|
|
router.goBack();
|
|
return renderFlash("error", "Unable to log out of your account");
|
|
}
|
|
};
|
|
|
|
logoutUser();
|
|
}, []);
|
|
|
|
return null;
|
|
};
|
|
|
|
export default LogoutPage;
|