Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/server/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function createAuth({
// 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),
(e: unknown) => console.error("[auth] failed to send sign-in code", e instanceof Error ? `${e.message}${e.cause ? ` (cause: ${String(e.cause)})` : ""}` : e),
);
try {
after(task);
Expand Down
6 changes: 5 additions & 1 deletion src/server/auth/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ export const sendMail: Mailer = async (message) => {
headers: { Authorization: `Bearer ${env.RESEND_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ from: env.MAIL_FROM, ...message }),
});
if (!res.ok) throw new Error(`Resend responded ${res.status}`);
if (!res.ok) {
// Resend's error body is {name, message} (e.g. "Invalid `from` field"): useful and free of secrets/OTPs.
const detail = await res.json().then((b: { name?: string; message?: string }) => `${b.name ?? ""}: ${b.message ?? ""}`).catch(() => "");
throw new Error(`Resend responded ${res.status} ${detail}`.trim());
}
};
Loading