SvelteKit Example

I was planning to do auth path check in
hooks.server.ts
, but don’t think I can with the
svelteKitHandler


So looks like what I need to do for SvelteKit, is do this on the root
layout.server.ts
and pass the session down.
await parent()


And do path check on each page or layout with the
session
passed down.

I hope there is a way to use the
auth.api
in
hooks.server.ts
instead. I planned on assigning the
auth.api
to
event.locals


Cause I’m assuming you can’t use the
auth.api
before the
svelteKitHander
.

Inspired by: https://youtu.be/K1Tya6ovVOI?feature=shared

Would love an example of this with Better Auth.
YouTubeHuntabyte
If you find my content useful and want to support the channel, consider contributing a coffee ☕: https://hbyt.us/coffee

SvelteKit is a framework for building modern, high-performance, browser-based applications. It was developed by the team behind the popular Svelte framework and is powered by Svelte. Unlike other JavaScript frameworks, it does...
Was this page helpful?
SvelteKit Example - Better Auth