cookies, headers and authentication
in express I can do something like
res.cookie("name", "value")
for example.
alternatively I can do res.set"set-cookie", "name=value")
.
how can I do something one of the two above with trpc?
or is there another, standardized way to do auth?
I'm using trpc v10 and sveltekit9 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ok, thank you! I'll try it out
my create context stuff is ran in
hooks.server.ts
like:
but a res
object is nowhere to be found. any idea how I can access it?Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I tried to pass the SvelteKit cookies object into the context, but it didn't work since SvelteKit resolves the response separately. I was able to set cookies directly in the response (not using SvelteKit's cookies object) in responseMeta by checking the response and paths, but that's kinda messy. I recommend keeping the auth logic on a +page.server.js or +server.js endpoint. tRPC for everything else.
There is the Lucia auth lib for SvelteKit: https://lucia-auth.vercel.app/
It sets some locals, it might be able to be passed to tRPC, but I haven't used it.
I have a repo for a custom auth with GitHub OAuth using endpoints as well and passes the session to the tRPC context, feel free to check it out https://github.com/austins/sveltekit-customauth
GitHub
GitHub - austins/sveltekit-customauth: An experiment.
An experiment. Contribute to austins/sveltekit-customauth development by creating an account on GitHub.
that helps, thank you
a bit annoying to do in the
+page.server.ts
but works 🤷‍♂️Balázs Orbán (@balazsorban44)
Announcing Auth.js! đź”’Authentication for the Web.
- Brand new
@​auth/core
package,
- Runtime/framework agnostic
- Web standard APIs
- Builds on NextAuth.js conventions/API
- Decoupled from Next.js & Node.js.
We're adding official support for new frameworks...Likes
412
Twitter
arrived right on time
That's awesome, thanks for sharing!