mirror of
https://github.com/JonasunderscoreJones/dash.jonasjones.dev.git
synced 2025-10-23 06:29:19 +02:00
moved session lib to $lib dir
This commit is contained in:
parent
a4e42be994
commit
9a2d157d37
4 changed files with 3 additions and 4 deletions
19
src/lib/session.js
Normal file
19
src/lib/session.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
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 ensureAuthenticated() {
|
||||
if (!getSessionKey()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue