mirror of
https://github.com/JonasunderscoreJones/dash.jonasjones.dev.git
synced 2025-10-22 21:29:19 +02:00
26 lines
No EOL
735 B
JavaScript
26 lines
No EOL
735 B
JavaScript
export const ACCOUNTS_WORKER_URL = 'https://accounts.jonasjones.dev';
|
|
|
|
export function getSessionKey() {
|
|
const match = document.cookie.match(/(^| )sessionKey=([^;]+)/);
|
|
return match ? match[2] : null;
|
|
}
|
|
|
|
export function setSessionKey(sessionKey) {
|
|
document.cookie = `sessionKey=${sessionKey}; path=/; max-age=604800`;
|
|
}
|
|
|
|
export function redirectToLogin() {
|
|
const currentPath = encodeURIComponent(window.location.pathname);
|
|
window.location.href = `/login?returnUrl=${currentPath}`;
|
|
}
|
|
|
|
export function resetSession() {
|
|
document.cookie = `sessionKey=; path=/; max-age=0`;
|
|
window.location.href = '/login';
|
|
}
|
|
|
|
export function ensureAuthenticated() {
|
|
if (!getSessionKey()) {
|
|
redirectToLogin();
|
|
}
|
|
} |