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

-8
View File
@@ -26,21 +26,13 @@ import { join } from 'node:path';
isGlobal: true,
cache: true,
}),
// Внутрипроцессная шина доменных событий. Notification-модуль слушает
// события через неё, не завязываясь на модули, которые их порождают.
EventEmitterModule.forRoot(),
// Периодические задачи (@Cron), например сборка файлов-сирот в FileModule
ScheduleModule.forRoot(),
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
sortSchema: true,
}),
// TypeOrmModule.forRootAsync({
// imports: [ConfigModule],
// inject: [ConfigService],
// useFactory: pgConfig,
// }),
AuthModule.forRoot({
auth: auth,
bodyParser: {
+1 -2
View File
@@ -1,7 +1,6 @@
import { ConfigService } from '@nestjs/config';
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
export function pgConfig(config: ConfigService): TypeOrmModuleOptions {
export function pgConfig(config: ConfigService): unknown {
return {
type: 'postgres',
url: config.getOrThrow<string>('DATABASE_URL'),
+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 });
-5
View File
@@ -16,12 +16,7 @@ async function bootstrap() {
logger: new CustomLogger(),
});
// app.useGlobalPipes(new StandardSchemaValidationPipe());
app.setGlobalPrefix('api');
// Глобальный body-parser отключён (better-auth сам парсит своё тело),
// поэтому для GraphQL включаем JSON-парсинг точечно на его пути.
app.use('/graphql', json());
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
app.useGlobalInterceptors(new TransformResponseInterceptor());