Auth through trpc procedures
Has Anyone Successfully Implemented Supabase Auth through tRPC Procedures in a Next.js App?
Hello everyone ๐,
I'm currently working on a Next.js project and trying to handle authentication using Supabase and tRPC. While I've been able to perform authentication directly via the Supabase client, I'm running into some issues when attempting to do the same through tRPC procedures. Specifically, sessions are not being added to cookies.
Here's a snippet of my tRPC auth service routes:
When I perform authentication directly using Supabase like so:
Everything works as expected. However, using my tRPC procedures doesn't seem to set the session in the cookies.
Has anyone faced a similar issue or successfully implemented this kind of setup? Any help would be much appreciated
5 Replies
which trpc link are you using? (httpLink, batchLink, httpBatchStreamLink, etc..)
if the link you are using provides a streamed response, then there is your problem since httpBatchStreamLink does not support setting headers once the stream has begun (thus you cannot set cookies on a response)
Unfortunately unstable_httpBatchStreamLink
https://github.com/wojtekKrol/NextBase-DevKit/blob/main/src/trpc/server-http.ts
GitHub
NextBase-DevKit/src/trpc/server-http.ts at main ยท wojtekKrol/NextBa...
Robust web application template built with Next.js, Drizzle ORM, Supabase, tRPC, Zod, React Query, and TailwindCSS. Designed for scalable and maintainable development, this template offers a custom...
Is it good idea to have separate api declaration with httpBatchLink just for actions that requires setting headers?
I think the easiest approach would be to just use a splitLink that uses httpBatchStreamLink for queries and httpBatchLink for mutations
something like that
I set up this but im not sure if it works I mean its set in my api definition for calling trpc on server components and im calling login mutation on client component