mirror of
https://github.com/JonasunderscoreJones/dash.jonasjones.dev.git
synced 2025-10-23 09:49:17 +02:00
initial project structure
This commit is contained in:
commit
3976aa6566
24 changed files with 1941 additions and 0 deletions
19
src/utils/session.js
Normal file
19
src/utils/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