File "cookies.ts"
Full Path: /var/www/html/gitep_front/src/features/authentication/lib/cookies.ts
File size: 976 bytes
MIME-type: text/x-java
Charset: utf-8
import Cookies from "js-cookie";
export const setCookie = (token: string, userId: string) => {
Cookies.set("token", token, { expires: 36500, path: "/" });
Cookies.set("userId", userId, { expires: 36500, path: "/" });
};
export const deleteCookie = () => {
const host = typeof window !== 'undefined' ? window.location.hostname : undefined;
const apex = host ? (host.split('.').length > 2 ? host.split('.').slice(-2).join('.') : host) : undefined;
const removeAll = (name: string) => {
Cookies.remove(name);
Cookies.remove(name, { path: "/" });
if (host) {
Cookies.remove(name, { domain: host, path: "/" });
Cookies.remove(name, { domain: host });
}
if (apex && apex !== host) {
Cookies.remove(name, { domain: apex, path: "/" });
Cookies.remove(name, { domain: apex });
Cookies.remove(name, { domain: `.${apex}`, path: "/" });
Cookies.remove(name, { domain: `.${apex}` });
}
};
removeAll("token");
};