Skip to content

Commit

Permalink
fix: latest resend not working in prod build
Browse files Browse the repository at this point in the history
  • Loading branch information
homocodian committed Aug 4, 2024
1 parent ab335a0 commit 88aef9f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"oslo": "^1.2.1",
"pg": "^8.12.0",
"postgres": "^3.4.4",
"resend": "^3.5.0",
"resend": "3.4.0",
"ua-parser-js": "^1.0.38",
"zod": "^3.23.8"
},
Expand Down
36 changes: 20 additions & 16 deletions apps/backend/src/v1/controllers/user/password-reset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { eq } from "drizzle-orm";
import { Context } from "elysia";
import { Context, error } from "elysia";

import { db } from "@/db";
import { userTable } from "@/db/schema/user";
Expand All @@ -22,23 +22,27 @@ export async function passwordReset(ctx: PasswordResetProps) {
return `If a ${env.APP_NAME} account exists for ${ctx.body.email}, an e-mail will be sent with further instructions.`;
}

const verificationToken = await createPasswordResetToken(user.id);
try {
const verificationToken = await createPasswordResetToken(user.id);

const verificationLink =
`${env.CLIENT_URL}/reset-password/` + verificationToken;
const verificationLink =
`${env.CLIENT_URL}/reset-password/` + verificationToken;

const { error } = await sendPasswordResetToken(
user.email,
verificationLink,
user.displayName
);

if (error) {
return ctx.error(
500,
"Unable to send reset link and it's not your fault, please try again later"
const { error } = await sendPasswordResetToken(
user.email,
verificationLink,
user.displayName
);
}

return `If a ${env.APP_NAME} account exists for ${ctx.body.email}, an e-mail will be sent with further instructions.`;
if (error) {
return ctx.error(
500,
"Unable to send reset link, please try again later"
);
}

return `If a ${env.APP_NAME} account exists for ${ctx.body.email}, an e-mail will be sent with further instructions.`;
} catch (err) {
return error(500, "Internal Server Error");
}
}
Binary file modified bun.lockb
Binary file not shown.

0 comments on commit 88aef9f

Please sign in to comment.