Skip to content

Commit

Permalink
Fix for local dev
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Apr 27, 2024
1 parent 968ce43 commit 3854cbb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
12 changes: 5 additions & 7 deletions apps/web/src/api/trpc/routers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ export const authRouter = createTRPCRouter({

await db.insert(accountLoginCodes).values({ accountPk, code });

waitUntil(async () => {
await sendEmail({
type: "loginCode",
to: input.email,
subject: "Mattrax Login Code",
code,
});
sendEmail({
type: "loginCode",
to: input.email,
subject: "Mattrax Login Code",
code,
});

return { accountId };
Expand Down
5 changes: 3 additions & 2 deletions packages/trpc-server-function/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function flushResponse() {

export function waitUntil(promise: Promise<void> | (() => Promise<void>)) {
const waitUntil = getEvent().context?.waitUntil;
if (!waitUntil) throw new Error("Not found 'waitUtil'");
waitUntil(typeof promise === "function" ? promise() : promise);
const p = typeof promise === "function" ? promise() : promise;
if (waitUntil) waitUntil(p);
// Promises are eager so if we aren't in Cloudflare Workers, we don't need to await it.
}

0 comments on commit 3854cbb

Please sign in to comment.