From 46c2dcb69a039f7968101e90bbb05fbea729fafb Mon Sep 17 00:00:00 2001 From: Ismail Akintunde Date: Tue, 23 Jul 2024 14:53:45 +0100 Subject: [PATCH] fix: fixed required review changes --- config/appConfig.ts | 11 ----------- config/auth.config.ts | 5 +++++ package.json | 3 +-- src/app.module.ts | 3 ++- src/modules/auth/auth.module.ts | 7 ++++--- src/modules/user/dto/user-response.dto.ts | 2 +- src/modules/user/options/UserIdentifierOptions.ts | 8 ++++---- src/modules/user/user.service.ts | 4 ++-- 8 files changed, 19 insertions(+), 24 deletions(-) delete mode 100644 config/appConfig.ts create mode 100644 config/auth.config.ts diff --git a/config/appConfig.ts b/config/appConfig.ts deleted file mode 100644 index 7ed1bd3ff..000000000 --- a/config/appConfig.ts +++ /dev/null @@ -1,11 +0,0 @@ -import * as dotenv from 'dotenv'; - -dotenv.config(); - -export const appConfig = { - jwt: { - jwtSecret: process.env.JWT_SECRET, - jwtExpiry: process.env.JWT_EXPIRY_TIMEFRAME - } - -} \ No newline at end of file diff --git a/config/auth.config.ts b/config/auth.config.ts new file mode 100644 index 000000000..2042e8dc2 --- /dev/null +++ b/config/auth.config.ts @@ -0,0 +1,5 @@ +import { registerAs } from '@nestjs/config'; +export default registerAs('auth', () => ({ + jwtSecret: process.env.JWT_SECRET, + jwtExpiry: process.env.JWT_EXPIRY_TIMEFRAME, +})); \ No newline at end of file diff --git a/package.json b/package.json index 05a4c985c..5c273cf51 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,6 @@ "lint-staged": "^15.2.5", "prettier": "^3.0.0", "source-map-support": "^0.5.21", - "supertest": "^6.3.4", "ts-jest": "^29.1.0", "ts-loader": "^9.4.3", "ts-node": "^10.9.1", @@ -104,4 +103,4 @@ "lint-staged": { "**/*": "prettier --write --ignore-unknown" } -} +} \ No newline at end of file diff --git a/src/app.module.ts b/src/app.module.ts index 6580c527c..eebfd7802 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -10,6 +10,7 @@ import { SeedingModule } from './database/seeding/seeding.module'; import HealthController from './health.controller'; import { AuthModule } from './modules/auth/auth.module'; import { UserModule } from './modules/user/user.module'; +import authConfig from 'config/auth.config'; @Module({ providers: [ @@ -36,7 +37,7 @@ import { UserModule } from './modules/user/user.module'; */ envFilePath: ['.env.development.local', `.env.${process.env.PROFILE}`], isGlobal: true, - load: [serverConfig], + load: [serverConfig, authConfig], /** * See ".env.local" file to list all environment variables needed by the app */ diff --git a/src/modules/auth/auth.module.ts b/src/modules/auth/auth.module.ts index 200c202df..f56883c6a 100644 --- a/src/modules/auth/auth.module.ts +++ b/src/modules/auth/auth.module.ts @@ -4,12 +4,13 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { User } from '../user/entities/user.entity'; import { JwtModule } from '@nestjs/jwt'; import { PassportModule } from '@nestjs/passport'; -import { appConfig } from '../../../config/appConfig'; +import appConfig from '../../../config/auth.config'; import { Repository } from 'typeorm'; import AuthenticationService from './auth.service'; import UserService from '../user/user.service'; + @Module({ controllers: [RegistrationController], providers: [AuthenticationService, Repository, UserService], @@ -18,8 +19,8 @@ import UserService from '../user/user.service'; PassportModule, JwtModule.register({ global: true, - secret: appConfig.jwt.jwtSecret, - signOptions: { expiresIn: `${appConfig.jwt.jwtExpiry}s` }, + secret: (appConfig()).jwtSecret, + signOptions: { expiresIn: `${(appConfig()).jwtExpiry}s` }, }), ], }) diff --git a/src/modules/user/dto/user-response.dto.ts b/src/modules/user/dto/user-response.dto.ts index a3bc517ea..6878fc59f 100644 --- a/src/modules/user/dto/user-response.dto.ts +++ b/src/modules/user/dto/user-response.dto.ts @@ -1,4 +1,4 @@ import UserInterface from "../interfaces/UserInterface"; -type UserResponseDTO = Pick +type UserResponseDTO = Partial export default UserResponseDTO \ No newline at end of file diff --git a/src/modules/user/options/UserIdentifierOptions.ts b/src/modules/user/options/UserIdentifierOptions.ts index 94566858d..38ef335bf 100644 --- a/src/modules/user/options/UserIdentifierOptions.ts +++ b/src/modules/user/options/UserIdentifierOptions.ts @@ -1,10 +1,10 @@ -type UserIdentifierOptions = { +type UserIdentifierOptionsType = { identifierType: "id", identifier: string -} | - { +} | +{ identifierType: "email", identifier: string } -export default UserIdentifierOptions \ No newline at end of file +export default UserIdentifierOptionsType \ No newline at end of file diff --git a/src/modules/user/user.service.ts b/src/modules/user/user.service.ts index 2cccac903..7379d9cdd 100644 --- a/src/modules/user/user.service.ts +++ b/src/modules/user/user.service.ts @@ -3,7 +3,7 @@ import { User } from './entities/user.entity'; import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import CreateNewUserOptions from './options/CreateNewUserOptions'; -import UserIdentifierOptions from './options/UserIdentifierOptions'; +import UserIdentifierOptionsType from './options/UserIdentifierOptions'; import UserResponseDTO from './dto/user-response.dto'; @@ -30,7 +30,7 @@ export default class UserService { return user } - async getUserRecord(identifierOptions: UserIdentifierOptions) { + async getUserRecord(identifierOptions: UserIdentifierOptionsType) { const { identifier, identifierType } = identifierOptions const GetRecord = {