fleet/frontend/utilities/auth_token/index.ts
Gabriel Hernandez aefad76342
extend the expiration date for the auth token cookie (#41261)
**Related issue:** Resolves #41262

This extends the expiration date for the host auth token cookie.

# Checklist for submitter

- [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
2026-03-10 17:15:09 +00:00

34 lines
746 B
TypeScript

/**
* This contains a collection of utility functions for working with
* users auth token.
*/
import Cookie from "js-cookie";
const DEFAULT_EXPIRATION_DAYS = 5;
const save = (token: string, expiresAt?: Date): void => {
Cookie.set("__Host-token", token, {
secure: true,
sameSite: "lax",
expires: expiresAt ?? DEFAULT_EXPIRATION_DAYS,
});
};
const get = (): string | null => {
return Cookie.get("__Host-token") || null;
};
const remove = (): void => {
// NOTE: the secure and sameSite from the cookie must be provided
// to correctly remove. That is why we include the options here as well.
Cookie.remove("__Host-token", {
secure: true,
sameSite: "lax",
});
};
export default {
save,
get,
remove,
};