mirror of
https://github.com/fosrl/pangolin.git
synced 2025-06-23 13:48:51 +02:00
fix issues from test deploy
This commit is contained in:
parent
3fb3be1f1e
commit
ce5df3b0b9
92 changed files with 1410 additions and 1019 deletions
48
server/auth/sendEmailVerificationCode.ts
Normal file
48
server/auth/sendEmailVerificationCode.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { TimeSpan, createDate } from "oslo";
|
||||
import { generateRandomString, alphabet } from "oslo/crypto";
|
||||
import db from "@server/db";
|
||||
import { users, emailVerificationCodes } from "@server/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { sendEmail } from "@server/emails";
|
||||
import config from "@server/config";
|
||||
import { VerifyEmail } from "@server/emails/templates/VerifyEmailCode";
|
||||
|
||||
export async function sendEmailVerificationCode(
|
||||
email: string,
|
||||
userId: string
|
||||
): Promise<void> {
|
||||
const code = await generateEmailVerificationCode(userId, email);
|
||||
|
||||
await sendEmail(
|
||||
VerifyEmail({
|
||||
username: email,
|
||||
verificationCode: code,
|
||||
verifyLink: `${config.app.base_url}/auth/verify-email`
|
||||
}),
|
||||
{
|
||||
to: email,
|
||||
from: config.email?.no_reply,
|
||||
subject: "Verify your email address"
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async function generateEmailVerificationCode(
|
||||
userId: string,
|
||||
email: string
|
||||
): Promise<string> {
|
||||
await db
|
||||
.delete(emailVerificationCodes)
|
||||
.where(eq(emailVerificationCodes.userId, userId));
|
||||
|
||||
const code = generateRandomString(8, alphabet("0-9"));
|
||||
|
||||
await db.insert(emailVerificationCodes).values({
|
||||
userId,
|
||||
email,
|
||||
code,
|
||||
expiresAt: createDate(new TimeSpan(15, "m")).getTime()
|
||||
});
|
||||
|
||||
return code;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue