tRPCttRPC
Powered by
benfahB
tRPC•15mo ago
benfah

tRPC mutation finishes early

Hi everybody,
I'm currently trying to use a tRPC mutation I wrote to log in to supabase. After some trial and error I found out that my defined mutation somehow finishes early, meaning it doesn't wait for any awaits to finish and also does not respect the output of the function, which means the body of the tRPC mutation is always empty.

export const authRouter = createTRPCRouter({
  login: publicProcedure.input(loginSchema).mutation(async ({ ctx, input }) => {
    await sleep(10000); //that was added in to see if the request takes 10s, which it doesn't
    const client = ctx.supabase;
    const { error, data } = await client.auth.signInWithPassword({
      email: input.email,
      password: input.password,
    });
    if (error)
      throw new TRPCError({
        code: "UNAUTHORIZED",
        cause: error,
        message: "Not authorized.",
      });
    return data;
  }),
});
export const authRouter = createTRPCRouter({
  login: publicProcedure.input(loginSchema).mutation(async ({ ctx, input }) => {
    await sleep(10000); //that was added in to see if the request takes 10s, which it doesn't
    const client = ctx.supabase;
    const { error, data } = await client.auth.signInWithPassword({
      email: input.email,
      password: input.password,
    });
    if (error)
      throw new TRPCError({
        code: "UNAUTHORIZED",
        cause: error,
        message: "Not authorized.",
      });
    return data;
  }),
});

Does anyone know what I can do to make the mutation await the calls?
If anyone needs some other information just let me know!
Thanks!
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

trpc mutation call stuck
juicoJjuico / ❓-help
3y ago
Use mutation trpc with nextJs
Answer OverflowAAnswer Overflow / ❓-help
3y ago