mirror of
https://github.com/JonasunderscoreJones/dash.jonasjones.dev.git
synced 2025-10-22 21:29:19 +02:00
added logout functionality
This commit is contained in:
parent
9a2d157d37
commit
e032477540
3 changed files with 20 additions and 0 deletions
|
@ -12,6 +12,11 @@ export function redirectToLogin() {
|
||||||
window.location.href = `/login?returnUrl=${currentPath}`;
|
window.location.href = `/login?returnUrl=${currentPath}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function resetSession() {
|
||||||
|
document.cookie = `sessionKey=; path=/; max-age=0`;
|
||||||
|
window.location.href = '/login';
|
||||||
|
}
|
||||||
|
|
||||||
export function ensureAuthenticated() {
|
export function ensureAuthenticated() {
|
||||||
if (!getSessionKey()) {
|
if (!getSessionKey()) {
|
||||||
redirectToLogin();
|
redirectToLogin();
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
<li aria-current={page.url.pathname === '/about' ? 'page' : undefined}>
|
<li aria-current={page.url.pathname === '/about' ? 'page' : undefined}>
|
||||||
<a href="/about">About</a>
|
<a href="/about">About</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li aria-current={page.url.pathname === '/logout' ? 'page' : undefined}>
|
||||||
|
<a href="/logout">Logout</a>
|
||||||
|
</li>
|
||||||
{/if}
|
{/if}
|
||||||
</ul>
|
</ul>
|
||||||
<svg viewBox="0 0 2 3" aria-hidden="true">
|
<svg viewBox="0 0 2 3" aria-hidden="true">
|
||||||
|
|
12
src/routes/logout/+page.svelte
Normal file
12
src/routes/logout/+page.svelte
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<script>
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
|
import { resetSession } from '$lib/session.js';
|
||||||
|
|
||||||
|
resetSession();
|
||||||
|
goto('/login');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h1>Logging out...</h1>
|
||||||
|
<p>Redirecting to the login page...</p>
|
||||||
|
</div>
|
Loading…
Add table
Add a link
Reference in a new issue