feat(auth): add Auth service and module
A new authentication service and module were added to the application. The app.module.ts file was updated to include this newly created AuthModule. Also, an initial structure for the AuthService was set up.
This commit is contained in:
parent
3c57098bbe
commit
bb482fb896
@ -2,7 +2,7 @@ import { defineConfig } from 'drizzle-kit';
|
||||
import * as process from "node:process";
|
||||
|
||||
export default defineConfig({
|
||||
schema: './src/drizzle/schema.ts',
|
||||
schema: './src/schema.ts',
|
||||
out: './drizzle',
|
||||
dialect: 'postgresql',
|
||||
dbCredentials: {
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { DrizzleService } from './drizzle.service';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { ConfigModule } from "@nestjs/config";
|
||||
import { DrizzleService } from "./drizzle.service";
|
||||
|
||||
@Module({
|
||||
imports: [ConfigModule],
|
||||
providers: [DrizzleService],
|
||||
exports: [DrizzleService]
|
||||
imports: [ConfigModule],
|
||||
providers: [DrizzleService],
|
||||
exports: [DrizzleService],
|
||||
})
|
||||
export class DrizzleModule {}
|
||||
|
@ -1,56 +1,52 @@
|
||||
// biome-ignore lint/style/useImportType: used by Next.js
|
||||
import { Injectable, OnModuleInit, OnModuleDestroy } from "@nestjs/common";
|
||||
import { Injectable, OnModuleDestroy, OnModuleInit } from "@nestjs/common";
|
||||
// biome-ignore lint/style/useImportType: used by Next.js
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||
import { migrate } from 'drizzle-orm/postgres-js/migrator';
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import { migrate } from "drizzle-orm/postgres-js/migrator";
|
||||
import postgres from "postgres";
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class DrizzleService implements OnModuleInit, OnModuleDestroy {
|
||||
private migrationClient: postgres.Sql<Record<string, postgres.PostgresType>>;
|
||||
private standardClient: postgres.Sql<Record<string, postgres.PostgresType>>;
|
||||
private migrationClient: postgres.Sql<Record<string, postgres.PostgresType>>;
|
||||
private standardClient: postgres.Sql<Record<string, postgres.PostgresType>>;
|
||||
|
||||
constructor(
|
||||
private configService: ConfigService
|
||||
) { }
|
||||
constructor(private configService: ConfigService) {}
|
||||
|
||||
async onModuleInit() {
|
||||
async onModuleInit() {
|
||||
const dbConfig = {
|
||||
host: this.configService.get<string>("POSTGRES_HOST"),
|
||||
port: Number(this.configService.get<string>("POSTGRES_PORT")),
|
||||
database: this.configService.get<string>("POSTGRES_DATABASE"),
|
||||
user: this.configService.get<string>("POSTGRES_USER"),
|
||||
password: this.configService.get<string>("POSTGRES_PASSWORD"),
|
||||
ssl: Boolean(this.configService.get<string>("POSTGRES_SSL")),
|
||||
};
|
||||
|
||||
const dbConfig = {
|
||||
host: this.configService.get<string>("POSTGRES_HOST"),
|
||||
port: Number(this.configService.get<string>("POSTGRES_PORT")),
|
||||
database: this.configService.get<string>("POSTGRES_DATABASE"),
|
||||
user: this.configService.get<string>("POSTGRES_USER"),
|
||||
password: this.configService.get<string>("POSTGRES_PASSWORD"),
|
||||
ssl: Boolean(this.configService.get<string>("POSTGRES_SSL")),
|
||||
}
|
||||
this.migrationClient = postgres({
|
||||
...dbConfig,
|
||||
max: 1,
|
||||
});
|
||||
|
||||
this.migrationClient = postgres({
|
||||
...dbConfig,
|
||||
max: 1,
|
||||
})
|
||||
this.standardClient = postgres({
|
||||
...dbConfig,
|
||||
});
|
||||
}
|
||||
|
||||
this.standardClient = postgres({
|
||||
...dbConfig
|
||||
})
|
||||
}
|
||||
//onModuleDestroy
|
||||
async onModuleDestroy() {
|
||||
await this.migrationClient.end();
|
||||
await this.standardClient.end();
|
||||
}
|
||||
|
||||
//onModuleDestroy
|
||||
async onModuleDestroy() {
|
||||
await this.migrationClient.end();
|
||||
await this.standardClient.end();
|
||||
}
|
||||
getMigrationClient() {
|
||||
return migrate(drizzle(this.migrationClient), {
|
||||
migrationsFolder: "./migrations",
|
||||
migrationsSchema: "public",
|
||||
});
|
||||
}
|
||||
|
||||
getMigrationClient() {
|
||||
return migrate(drizzle(this.migrationClient), {
|
||||
migrationsFolder: "./migrations",
|
||||
migrationsSchema: "public"
|
||||
});
|
||||
}
|
||||
|
||||
getClient() {
|
||||
return drizzle(this.standardClient);
|
||||
}
|
||||
}
|
||||
use() {
|
||||
return drizzle(this.standardClient);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user