Reputation: 3
I created a tRPC mutation to verify an email on my database called verificateEmailProcedure. I have a middleware that runs on every route of my app and it was blocking this procedure. Every route in my app is protected except a few and verificateEmailProcedure is one that does not need authentication. Upon further inspection I realized that I was getting blocked because the request was being made like this:
POST /api/trpc/verificateEmailProcedure,verificateEmailProcedure?batch=1 200 in 66ms
This is the declaration:
verificateEmailProcedure: publicProcedure
.input(z.object({ token: z.string() }))
.mutation(async (opts) => {
const { token } = opts.input;
const vt = await getVerificationTokenByToken(token);
if (!vt) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "Token does not exists",
});
}
if (new Date().getTime() > vt.expires.getTime()) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "Token has expired",
});
}
const user = await getUserByEmail(vt.email);
if (!user) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "Email does not exists",
});
}
await validateEmail(user.id, vt.email);
await deleteToken(vt.id);
return "Email verified";
}),
Somehow tRPC knows which procedure to call even if the URL is like this so everything works when I deactivate the middleware. Any idea why the procedure repeats itself in the URL?
Upvotes: 0
Views: 37