MarM
tRPCโ€ข3y agoโ€ข
9 replies
Mar

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:

export const authServiceRoutes = router({
  signup: publicProcedure
    .input(SignupInput)
    .mutation(async ({ ctx: { supabase }, input: { email, password } }) => {
      // Signup Logic
    }),
  login: publicProcedure
    .input(LoginInput)
    .mutation(async ({ ctx: { supabase }, input: { email, password } }) => {
      // Login Logic
    })
})


When I perform authentication directly using Supabase like so:

await supabase.auth.signInWithPassword({ email, password });


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
Was this page helpful?