Rework admin panel and other
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// utils/cookies.js
|
||||
export const setCookie = (name, value, days) => {
|
||||
let expires = "";
|
||||
if (days) {
|
||||
const date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
expires = "; expires=" + date.toUTCString();
|
||||
}
|
||||
document.cookie = name + "=" + (value || "") + expires + "; path=/";
|
||||
};
|
||||
|
||||
export const getCookie = (name) => {
|
||||
const nameEQ = name + "=";
|
||||
const ca = document.cookie.split(';');
|
||||
for (let i = 0; i < ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export const deleteCookie = (name) => {
|
||||
const domain = window.location.hostname.includes('.') ? '.' + window.location.hostname : window.location.hostname;
|
||||
document.cookie = name + '=; Max-Age=-99999999; path=/; domain=' + domain;
|
||||
};
|
||||
|
||||
export const deleteCookiesWithPrefix = (prefix) => {
|
||||
const cookies = document.cookie.split(';');
|
||||
for (let cookie of cookies) {
|
||||
const cookieName = cookie.split('=')[0].trim();
|
||||
if (cookieName.startsWith(prefix)) {
|
||||
deleteCookie(cookieName);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user