mirror of
https://github.com/JonasunderscoreJones/dash.jonasjones.dev.git
synced 2025-10-22 21:09:20 +02:00
added redirect from login if sessionKey present
This commit is contained in:
parent
e5c9c351e7
commit
f0eedba287
2 changed files with 14 additions and 1 deletions
|
@ -19,6 +19,15 @@ export function resetSession() {
|
|||
window.location.href = '/login';
|
||||
}
|
||||
|
||||
export function redirectToHome() {
|
||||
if (getSessionKey()) {
|
||||
window.location.href = new URLSearchParams(window.location.search).get('returnUrl') || '/';
|
||||
console.log(new URLSearchParams(window.location.search).get('returnUrl') || '/')
|
||||
} else {
|
||||
console.log(getSessionKey())
|
||||
}
|
||||
}
|
||||
|
||||
export function ensureAuthenticated() {
|
||||
if (!getSessionKey()) {
|
||||
redirectToLogin();
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
<script>
|
||||
import { navigate } from 'svelte-routing';
|
||||
import { onMount } from 'svelte';
|
||||
import { setSessionKey, ACCOUNTS_WORKER_URL } from '$lib/session.js';
|
||||
import { setSessionKey, redirectToHome, ACCOUNTS_WORKER_URL } from '$lib/session.js';
|
||||
import { page } from '$app/state';
|
||||
let email = '';
|
||||
let password = '';
|
||||
let errorMessage = '';
|
||||
let showPassword = false;
|
||||
|
||||
onMount(() => {
|
||||
redirectToHome(); // This will check the session key and redirect if necessary
|
||||
});
|
||||
|
||||
const handleLogin = async () => {
|
||||
try {
|
||||
const response = await fetch(ACCOUNTS_WORKER_URL + '/login', {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue