© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•5mo ago•
3 replies
Tamaro "Kor Sharoth" Skaljic

SvelteKit Server Side Authentication

I've followed the SvelteKit Server Side Authentication Guide and left with more questions than answers.

- We're creating a Supabase Server Client in the Supabase Hook in
hooks.server.ts
hooks.server.ts
.
- Then we're calling
event.locals.safeGetSession()
event.locals.safeGetSession()
and set
event.locals.session
event.locals.session
and
event.locals.user
event.locals.user
in the auth hook, also in hooks.server.ts.

- We're calling
event.locals.safeGetSession
event.locals.safeGetSession
again in
+layout.server.ts
+layout.server.ts
and return the session we got. Why doesn't we just return the
event.locals.session
event.locals.session
already set in the auth hook?

- In
+layout.ts
+layout.ts
(which run's both on server and client),
- on the server we're creating another Supabase Server client and get session and user again. Why? Until now we've called getUser and getSession 6 times on the server - auth hook in hooks.server.ts, server load in +layout.server.ts and server load here again.
- on the client we're creating a Supabase Browser client and get session and user again. But from my understanding this code isn't called when the layout loads the first time (because the ssr version ran), but instead when the auth state changes (because of the
+layout.svelte
+layout.svelte
).
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Sveltekit Server side authentication
SupabaseSSupabase / help-and-questions
2mo ago
SvelteKit and Authentication—server- or client-side?
SupabaseSSupabase / help-and-questions
4y ago
Documentation for full client side authentication with SvelteKit
SupabaseSSupabase / help-and-questions
3y ago
SSR authentication on SvelteKit
SupabaseSSupabase / help-and-questions
3y ago