otp code, packages update
Gitea Actions / Deploy (push) Successful in 1m34s

This commit is contained in:
vadim committed 2026-10-19 17:23:50 +03:00
1 parent c5691da2b8
commit de1b3754df
6 files changed
+949 -1165

No files matched your search

+22 -1
View File
@@ -2,12 +2,33 @@ import { betterAuth } from 'better-auth';
import { prismaAdapter } from '@better-auth/prisma-adapter';
import prisma from './prisma.js';
import EmailSender from './email-sender.js';
import { emailOTP } from 'better-auth/plugins';
export const auth = betterAuth({
appName: process.env.APP_NAME ?? 'app',
basePath: '/api/auth',
plugins: [
// authTransformResponse()
emailOTP({
async sendVerificationOTP({ email, otp, type }) {
if (type === 'sign-in') {
// Send the OTP for sign in
console.log({ email, otp, type });
void EmailSender.getTransporter().sendMail({
to: email,
subject: `Your OTP code is: ${otp}`,
text: `Your OTP code is: ${otp}`,
});
} else if (type === 'email-verification') {
// Send the OTP for email verification
console.log({ email, otp, type });
} else {
// Send the OTP for password reset
console.log({ email, otp, type });
}
},
}),
],
database: prismaAdapter(prisma, {
provider: 'postgresql',
@@ -24,7 +45,7 @@ export const auth = betterAuth({
emailAndPassword: {
enabled: true,
autoSignIn: false,
requireEmailVerification: false,
requireEmailVerification: true,
onExistingUserSignUp: async ({ user }, request) => {
console.log('onExistingUserSignUp', { user });