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";
|
import * as process from "node:process";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
schema: './src/drizzle/schema.ts',
|
schema: './src/schema.ts',
|
||||||
out: './drizzle',
|
out: './drizzle',
|
||||||
dialect: 'postgresql',
|
dialect: 'postgresql',
|
||||||
dbCredentials: {
|
dbCredentials: {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from "@nestjs/common";
|
||||||
import { DrizzleService } from './drizzle.service';
|
|
||||||
import { ConfigModule } from "@nestjs/config";
|
import { ConfigModule } from "@nestjs/config";
|
||||||
|
import { DrizzleService } from "./drizzle.service";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ConfigModule],
|
imports: [ConfigModule],
|
||||||
providers: [DrizzleService],
|
providers: [DrizzleService],
|
||||||
exports: [DrizzleService]
|
exports: [DrizzleService],
|
||||||
})
|
})
|
||||||
export class DrizzleModule {}
|
export class DrizzleModule {}
|
||||||
|
@ -1,23 +1,19 @@
|
|||||||
// biome-ignore lint/style/useImportType: used by Next.js
|
// 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
|
// biome-ignore lint/style/useImportType: used by Next.js
|
||||||
import { ConfigService } from "@nestjs/config";
|
import { ConfigService } from "@nestjs/config";
|
||||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
import { drizzle } from "drizzle-orm/postgres-js";
|
||||||
import { migrate } from 'drizzle-orm/postgres-js/migrator';
|
import { migrate } from "drizzle-orm/postgres-js/migrator";
|
||||||
import postgres from "postgres";
|
import postgres from "postgres";
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DrizzleService implements OnModuleInit, OnModuleDestroy {
|
export class DrizzleService implements OnModuleInit, OnModuleDestroy {
|
||||||
private migrationClient: postgres.Sql<Record<string, postgres.PostgresType>>;
|
private migrationClient: postgres.Sql<Record<string, postgres.PostgresType>>;
|
||||||
private standardClient: postgres.Sql<Record<string, postgres.PostgresType>>;
|
private standardClient: postgres.Sql<Record<string, postgres.PostgresType>>;
|
||||||
|
|
||||||
constructor(
|
constructor(private configService: ConfigService) {}
|
||||||
private configService: ConfigService
|
|
||||||
) { }
|
|
||||||
|
|
||||||
async onModuleInit() {
|
async onModuleInit() {
|
||||||
|
|
||||||
const dbConfig = {
|
const dbConfig = {
|
||||||
host: this.configService.get<string>("POSTGRES_HOST"),
|
host: this.configService.get<string>("POSTGRES_HOST"),
|
||||||
port: Number(this.configService.get<string>("POSTGRES_PORT")),
|
port: Number(this.configService.get<string>("POSTGRES_PORT")),
|
||||||
@ -25,16 +21,16 @@ export class DrizzleService implements OnModuleInit, OnModuleDestroy {
|
|||||||
user: this.configService.get<string>("POSTGRES_USER"),
|
user: this.configService.get<string>("POSTGRES_USER"),
|
||||||
password: this.configService.get<string>("POSTGRES_PASSWORD"),
|
password: this.configService.get<string>("POSTGRES_PASSWORD"),
|
||||||
ssl: Boolean(this.configService.get<string>("POSTGRES_SSL")),
|
ssl: Boolean(this.configService.get<string>("POSTGRES_SSL")),
|
||||||
}
|
};
|
||||||
|
|
||||||
this.migrationClient = postgres({
|
this.migrationClient = postgres({
|
||||||
...dbConfig,
|
...dbConfig,
|
||||||
max: 1,
|
max: 1,
|
||||||
})
|
});
|
||||||
|
|
||||||
this.standardClient = postgres({
|
this.standardClient = postgres({
|
||||||
...dbConfig
|
...dbConfig,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//onModuleDestroy
|
//onModuleDestroy
|
||||||
@ -46,11 +42,11 @@ export class DrizzleService implements OnModuleInit, OnModuleDestroy {
|
|||||||
getMigrationClient() {
|
getMigrationClient() {
|
||||||
return migrate(drizzle(this.migrationClient), {
|
return migrate(drizzle(this.migrationClient), {
|
||||||
migrationsFolder: "./migrations",
|
migrationsFolder: "./migrations",
|
||||||
migrationsSchema: "public"
|
migrationsSchema: "public",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getClient() {
|
use() {
|
||||||
return drizzle(this.standardClient);
|
return drizzle(this.standardClient);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user