12 lines
488 B
TypeScript
12 lines
488 B
TypeScript
export const hasAuthCookie = () => {
|
|
const matches = document.cookie.match(/^(.*;)?\s*payload-token\s*=\s*[^;]+(.*)?$/) || []
|
|
const hasMatch = matches.length > 0
|
|
return hasMatch;
|
|
}
|
|
|
|
export const setAuthCookie = (value: string, expirationDays: number) => {
|
|
const date = new Date();
|
|
date.setTime(date.getTime() + (expirationDays * 24 * 60 * 60 * 1000));
|
|
const expires = "expires=" + date.toUTCString();
|
|
document.cookie = "payload-token=" + value + ";" + expires + ";path=/";
|
|
} |