Skip to content

Commit 8a9604d

Browse files
committed
This should be fineeee
1 parent 74caa55 commit 8a9604d

3 files changed

Lines changed: 8 additions & 23 deletions

File tree

src/routes/(anonymous)/+layout.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { redirect } from '@sveltejs/kit';
33
export async function load({ cookies, url }) {
44
const cookieValue = cookies.get('openShockSession');
55
if (cookieValue !== undefined && cookieValue !== null) {
6-
redirect(302, url.searchParams.get('redirect') ?? '/home');
6+
redirect(303, url.searchParams.get('redirect') ?? '/home');
77
}
88
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { redirect } from '@sveltejs/kit';
2+
3+
export function load({ cookies, url }) {
4+
if (!cookies.get('openShockSession')) {
5+
redirect(303, `/login?redirect=${url.pathname}`);
6+
}
7+
}
Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
import { browser } from '$app/environment';
2-
import { goto } from '$app/navigation';
3-
import { destroyAuth } from '$lib/init';
4-
import { UserStore } from '$lib/stores/UserStore';
5-
import { get } from 'svelte/store';
6-
71
// The pages below this one will be different from user-to-user so cannot be prerendered and really shouldnt be server rendered
82
export const ssr = false; // Only render authenticated pages in browser
93
export const prerender = false;
10-
11-
// Initialize stores and signalr on auth
12-
export async function load({ url }) {
13-
if (!browser) return; // Yeah please dont run on server
14-
15-
// On loading in the anonymous section, check if cookie is set, if it is send us to the authenticated section
16-
if (!get(UserStore).self) {
17-
try {
18-
await destroyAuth();
19-
} catch (error) {
20-
console.error(error);
21-
} finally {
22-
goto(`/login?redirect=${url.pathname}`);
23-
}
24-
}
25-
}

0 commit comments

Comments
 (0)