Replies: 1 comment
-
|
Related - #6051 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm getting unexpected behavior - probably because I don't know how this works.
Here's my route structure:
/login, there's a login button for github oauth.+layout.svelteknows someone's now logged in.That's when this code runs:
The
hook.jshandle()is reading the cookie and passing data toevent.locals.In
+layout.server.js, I'm returning asessionobject fromevent.locals, to read asdata.sessionin+layout.svelte.I'm logging various points in the flow, and now get this output of what's happening when the code above is run. I suspect the first three lines are because of what supabase is doing to execute the login and callback.
What I'm not understanding is why
app/+page.server.jsis logging before+layout.server.js- implying it's running before+layout.server.js.What's interesting is that when I click the logout button, I run
await invalidate()and thengoto('/'), but the logs on this always show+layout.server.jsfirst.Also, when the login process and code finishes, two parts of the app should now reflect that a user is logged in:
/app/+page.sveltewill now show user data/+layout.sveltewill now show a logout button in the navbar.However, with the code above, only the /app page will render user data.
If I change
await invalidate('/')toawait invalidate(), then both will happen.What am I not understanding? Thanks!
Update
Actually, if I read the docs really slow - like two times, I might know what's going on with
invalidate().I'm now thinking that
'/'would only re-runloadin/+page.server.js, and doesn't touchloadin+layout.server.js. But once I remove the'/'frominvalidate('/')the remaininginvalidate()also runs theloadfunction in+layout.server.js, hence updating data in+layout.svelteand properly showing the logout button becausedata.sessionis populated.Beta Was this translation helpful? Give feedback.
All reactions