Skip to content
Discussion options

You must be logged in to vote

Seems like I was a little bit sleepy yesterday... I'm sure I checked this approach as well at some point.

Solution

routes/+layout.ts

import { handleRouting, RouteType } from '$lib/utils/route';
import type { LayoutLoad } from './$types';
import { goto } from '$app/navigation';
import { get } from 'svelte/store';
import { userStore } from '$lib/stores/user';

export const ssr = false;

export const load = (async ({ route }) => {
    const routeType = handleRouting(route.id || '')
    const user = get(userStore);
    const isUserLoggedIn = user.user_id !== '';
    if (routeType === RouteType.PAGE_PROTECTED) {
        if (!isUserLoggedIn) {
            console.log("forwarding to /login")

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@0djek
Comment options

@LukaHarambasic
Comment options

@dummdidumm
Comment options

Answer selected by LukaHarambasic
Comment options

You must be logged in to vote
1 reply
@LukaHarambasic
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants