mirror of
https://github.com/JonasunderscoreJones/dash.jonasjones.dev.git
synced 2025-10-23 00:09:19 +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';
|
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() {
|
export function ensureAuthenticated() {
|
||||||
if (!getSessionKey()) {
|
if (!getSessionKey()) {
|
||||||
redirectToLogin();
|
redirectToLogin();
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
<script>
|
<script>
|
||||||
import { navigate } from 'svelte-routing';
|
import { navigate } from 'svelte-routing';
|
||||||
import { onMount } from 'svelte';
|
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';
|
import { page } from '$app/state';
|
||||||
let email = '';
|
let email = '';
|
||||||
let password = '';
|
let password = '';
|
||||||
let errorMessage = '';
|
let errorMessage = '';
|
||||||
let showPassword = false;
|
let showPassword = false;
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
redirectToHome(); // This will check the session key and redirect if necessary
|
||||||
|
});
|
||||||
|
|
||||||
const handleLogin = async () => {
|
const handleLogin = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(ACCOUNTS_WORKER_URL + '/login', {
|
const response = await fetch(ACCOUNTS_WORKER_URL + '/login', {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue