Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/server/auth/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { nextCookies } from "better-auth/next-js";
import { after } from "next/server";
import { emailOTP, organization } from "better-auth/plugins";
import { and, asc, eq, isNull } from "drizzle-orm";
import { getDb, type Db } from "@/db";
Expand Down Expand Up @@ -71,10 +72,16 @@ export function createAuth({
expiresIn: 300,
allowedAttempts: 3,
async sendVerificationOTP({ email, otp }) {
// Not awaited on purpose (timing attacks). Errors are logged without the message body.
void send({ to: email, subject: "Seu código de acesso ao Compasso", text: `Seu código: ${otp}\nVálido por 5 minutos.` }).catch(
// Not awaited on purpose (timing attacks), but kept alive with after(): on Vercel the function can be frozen
// as soon as the response is sent, which silently drops a fire-and-forget fetch. Errors never include the body.
const task = send({ to: email, subject: "Seu código de acesso ao Compasso", text: `Seu código: ${otp}\nVálido por 5 minutos.` }).catch(
(e: unknown) => console.error("[auth] failed to send sign-in code", e instanceof Error ? e.message : e),
);
try {
after(task);
} catch {
// outside a request scope (tests, scripts): the promise simply runs on its own
}
},
}),
organization({
Expand Down
Loading