SvelteKit __layout slot session

Viewed 189

I have index file in routes, where is just navigation to /auth or /home when user has or does not have set cookie.

<script context="module">
export async function load({ session }) {
    if (session.user.token != null) {
        return {
            status: 302,
            redirect: '/home'
        };
    } else
        return {
            status: 302,
            redirect: '/auth'
        };
}

It's working just fine, but the problem I have starts in /home path. /home, /a and /b have the same structure, so I thought I made __layout file where these pages will be injected into a slot. It's working, but the problem is with updating $session. After login, the profileimage from session is not updated and is not set, even though it is set (debugged via dev tools). After reloading the page, image is correctly shown.

Is it possible to reload the __layout or there is better way to do it? I'm beginner in web apps.

<body>
<div class="flex h-screen bg-gray-50 ">
    <Navbar />
    <NavbarPanel imageUrl={$session.user.profileimage}>
        <slot />
    </NavbarPanel>
</div>
0 Answers
Related