diff --git a/docs/swagger/swagger-spec.json b/docs/swagger/swagger-spec.json index f0c9119..dad070b 100644 --- a/docs/swagger/swagger-spec.json +++ b/docs/swagger/swagger-spec.json @@ -545,9 +545,6 @@ ] } }, -<<<<<<< HEAD - "/auth/v1/login": { -======= "/Expenses": { "post": { "operationId": "ExpensesController_create", @@ -1144,8 +1141,7 @@ ] } }, - "/auth/login": { ->>>>>>> b0406b3a4c00223b9430ef29b60a4775beca4328 + "/auth/v1/login": { "get": { "operationId": "AuthController_login", "parameters": [], diff --git a/src/common/guards/roles.guard.ts b/src/common/guards/roles.guard.ts index eba4e99..61889f7 100644 --- a/src/common/guards/roles.guard.ts +++ b/src/common/guards/roles.guard.ts @@ -7,12 +7,12 @@ import { import { Reflector } from '@nestjs/core'; import { ROLES_KEY } from '../decorators/roles.decorators'; import { Roles } from '.prisma/client'; -import { JwtPayload } from 'src/modules/authentication/strategies/jwt.strategy'; interface RequestWithUser extends Request { - user: JwtPayload; + // TODO: Create an actual user model based on OAuth signin + user: any; } @Injectable() diff --git a/src/modules/archival/controllers/employees-archive.controller.ts b/src/modules/archival/controllers/employees-archive.controller.ts index 07ec791..1de0749 100644 --- a/src/modules/archival/controllers/employees-archive.controller.ts +++ b/src/modules/archival/controllers/employees-archive.controller.ts @@ -2,11 +2,10 @@ import { Controller, Get, NotFoundException, Param, ParseIntPipe, UseGuards } fr import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; import { RolesAllowed } from "src/common/decorators/roles.decorators"; import { EmployeesArchive, Roles as RoleEnum } from '@prisma/client'; -import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; import { EmployeesService } from "src/modules/employees/services/employees.service"; @ApiTags('Employee Archives') -@UseGuards(JwtAuthGuard) +// @UseGuards() @Controller('archives/employees') export class EmployeesArchiveController { constructor(private readonly employeesService: EmployeesService) {} diff --git a/src/modules/archival/controllers/expenses-archive.controller.ts b/src/modules/archival/controllers/expenses-archive.controller.ts index 01b544a..1e522bd 100644 --- a/src/modules/archival/controllers/expenses-archive.controller.ts +++ b/src/modules/archival/controllers/expenses-archive.controller.ts @@ -2,11 +2,10 @@ import { UseGuards, Controller, Get, Param, ParseIntPipe, NotFoundException } fr import { ApiTags, ApiOperation, ApiResponse } from "@nestjs/swagger"; import { ExpensesArchive,Roles as RoleEnum } from "@prisma/client"; import { RolesAllowed } from "src/common/decorators/roles.decorators"; -import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; import { ExpensesService } from "src/modules/expenses/services/expenses.service"; @ApiTags('Expense Archives') -@UseGuards(JwtAuthGuard) +// @UseGuards() @Controller('archives/expenses') export class ExpensesArchiveController { constructor(private readonly expensesService: ExpensesService) {} diff --git a/src/modules/archival/controllers/leave-requests-archive.controller.ts b/src/modules/archival/controllers/leave-requests-archive.controller.ts index b8f8399..27c7b94 100644 --- a/src/modules/archival/controllers/leave-requests-archive.controller.ts +++ b/src/modules/archival/controllers/leave-requests-archive.controller.ts @@ -2,11 +2,10 @@ import { Get, Param, ParseIntPipe, NotFoundException, Controller, UseGuards } fr import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; import { LeaveRequestsArchive, Roles as RoleEnum } from "@prisma/client"; import { RolesAllowed } from "src/common/decorators/roles.decorators"; -import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; import { LeaveRequestsService } from "src/modules/leave-requests/services/leave-requests.service"; @ApiTags('LeaveRequests Archives') -@UseGuards(JwtAuthGuard) +// @UseGuards() @Controller('archives/leaveRequests') export class LeaveRequestsArchiveController { constructor(private readonly leaveRequestsService: LeaveRequestsService) {} diff --git a/src/modules/archival/controllers/shifts-archive.controller.ts b/src/modules/archival/controllers/shifts-archive.controller.ts index d8fc568..5666646 100644 --- a/src/modules/archival/controllers/shifts-archive.controller.ts +++ b/src/modules/archival/controllers/shifts-archive.controller.ts @@ -2,11 +2,10 @@ import { Get, Param, ParseIntPipe, NotFoundException, Controller, UseGuards } fr import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; import { ShiftsArchive, Roles as RoleEnum } from "@prisma/client"; import { RolesAllowed } from "src/common/decorators/roles.decorators"; -import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; import { ShiftsService } from "src/modules/shifts/services/shifts.service"; @ApiTags('Shift Archives') -@UseGuards(JwtAuthGuard) +// @UseGuards() @Controller('archives/shifts') export class ShiftsArchiveController { constructor(private readonly shiftsService:ShiftsService) {} diff --git a/src/modules/archival/controllers/timesheets-archive.controller.ts b/src/modules/archival/controllers/timesheets-archive.controller.ts index 0fcb8e5..e2e1d20 100644 --- a/src/modules/archival/controllers/timesheets-archive.controller.ts +++ b/src/modules/archival/controllers/timesheets-archive.controller.ts @@ -3,10 +3,9 @@ import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; import { RolesAllowed } from "src/common/decorators/roles.decorators"; import { TimesheetsArchive, Roles as RoleEnum } from '@prisma/client'; import { TimesheetsService } from "src/modules/timesheets/services/timesheets.service"; -import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; @ApiTags('Timesheet Archives') -@UseGuards(JwtAuthGuard) +// @UseGuards() @Controller('archives/timesheets') export class TimesheetsArchiveController { constructor(private readonly timesheetsService: TimesheetsService) {} diff --git a/src/modules/authentication/auth.module.ts b/src/modules/authentication/auth.module.ts index 9b9b52e..784e22d 100644 --- a/src/modules/authentication/auth.module.ts +++ b/src/modules/authentication/auth.module.ts @@ -1,11 +1,10 @@ import { Module } from '@nestjs/common'; -import { JwtModule } from '@nestjs/jwt'; import { PassportModule } from '@nestjs/passport'; import { AuthentikAuthService } from './services/authentik-auth.service'; import { UsersModule } from '../users-management/users.module'; import { AuthController } from './controllers/auth.controller'; import { AuthentikStrategy } from './strategies/authentik.strategy'; -import { SessionSerializer } from './session.serializer'; +import { ExpressSessionSerializer } from './services/express-session.serializer'; @Module({ @@ -16,7 +15,7 @@ import { SessionSerializer } from './session.serializer'; providers: [ AuthentikAuthService, AuthentikStrategy, - SessionSerializer, + ExpressSessionSerializer, ], exports: [ AuthentikAuthService ], controllers: [AuthController], diff --git a/src/modules/authentication/authrequests.http b/src/modules/authentication/authrequests.http deleted file mode 100644 index a91dfcf..0000000 --- a/src/modules/authentication/authrequests.http +++ /dev/null @@ -1 +0,0 @@ -POST http://localhost:3000/auth/login \ No newline at end of file diff --git a/src/modules/authentication/guards/jwt-auth.guard.ts b/src/modules/authentication/guards/jwt-auth.guard.ts deleted file mode 100644 index dd21e87..0000000 --- a/src/modules/authentication/guards/jwt-auth.guard.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { ExecutionContext, Injectable, UnauthorizedException } from '@nestjs/common'; -import { AuthGuard } from '@nestjs/passport'; -import { Observable } from 'rxjs'; - -@Injectable() -export class JwtAuthGuard extends AuthGuard('jwt') { - - canActivate(context: ExecutionContext) { - return super.canActivate(context); - } - - handleRequest(err, user, info) { - if(err || !user) { - throw err || new UnauthorizedException(); - } - return user; - } -} diff --git a/src/modules/authentication/services/jwt-auth.service.ts b/src/modules/authentication/services/jwt-auth.service.ts deleted file mode 100644 index a4c65e2..0000000 --- a/src/modules/authentication/services/jwt-auth.service.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { UUID } from 'crypto'; -import { UsersService } from 'src/modules/users-management/services/users.service'; -import { JwtService } from '@nestjs/jwt'; - -@Injectable() -export class AuthService { - constructor( - private usersService: UsersService, - private jwtService: JwtService - ) {} - - async validateUser(user_id: UUID): Promise { - const user = await this.usersService.findOne( user_id ); - if (user) { - return user; - } - return null; - } -} diff --git a/src/modules/authentication/session.serializer.ts b/src/modules/authentication/session.serializer.ts deleted file mode 100644 index a1311cc..0000000 --- a/src/modules/authentication/session.serializer.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { PassportSerializer } from '@nestjs/passport'; -import { Injectable, UnauthorizedException } from '@nestjs/common'; - -@Injectable() -export class SessionSerializer extends PassportSerializer { - serializeUser(user: any, done: (err: any, user: any) => void): any { - if (!user){ - done(new UnauthorizedException('Serialize user error'), user); - } - done(null, user); - } - deserializeUser(payload: any, done: (err: any, payload: string) => void): any { - if (!payload){ - done(new UnauthorizedException('Deserialize user error'), payload); - } - done(null, payload); - } -} \ No newline at end of file diff --git a/src/modules/authentication/strategies/jwt.strategy.ts b/src/modules/authentication/strategies/jwt.strategy.ts deleted file mode 100644 index 3a2afb0..0000000 --- a/src/modules/authentication/strategies/jwt.strategy.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { PassportStrategy } from '@nestjs/passport'; -import { Roles } from '@prisma/client'; -import { ExtractJwt, Strategy } from 'passport-jwt'; - -export interface JwtPayload { - sub: number; - email: string; - role: Roles; -} - -@Injectable() -export class JwtStrategy extends PassportStrategy(Strategy) { - constructor() { - super({ - jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), - ignoreExpiration: false, - secretOrKey: process.env.JWT_SECRET || 'CHANGE_ME', - }); - } - - validate(payload: JwtPayload): JwtPayload { - return payload; - } -} diff --git a/src/modules/customers/controllers/customers.controller.ts b/src/modules/customers/controllers/customers.controller.ts index 66f216a..68ff7d3 100644 --- a/src/modules/customers/controllers/customers.controller.ts +++ b/src/modules/customers/controllers/customers.controller.ts @@ -6,12 +6,11 @@ import { UpdateCustomerDto } from '../dtos/update-customer.dto'; import { RolesAllowed } from "src/common/decorators/roles.decorators"; import { Roles as RoleEnum } from '.prisma/client'; import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; -import { JwtAuthGuard } from 'src/modules/authentication/guards/jwt-auth.guard'; import { CustomerEntity } from '../dtos/swagger-entities/customers.entity'; @ApiTags('Customers') @ApiBearerAuth('access-token') -@UseGuards(JwtAuthGuard) +// @UseGuards() @Controller('customers') export class CustomersController { constructor(private readonly customersService: CustomersService) {} diff --git a/src/modules/employees/controllers/employees.controller.ts b/src/modules/employees/controllers/employees.controller.ts index f0ba727..96f6e4a 100644 --- a/src/modules/employees/controllers/employees.controller.ts +++ b/src/modules/employees/controllers/employees.controller.ts @@ -5,12 +5,11 @@ import { CreateEmployeeDto } from '../dtos/create-employee.dto'; import { UpdateEmployeeDto } from '../dtos/update-employee.dto'; import { RolesAllowed } from '../../../common/decorators/roles.decorators'; import { ApiBearerAuth, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger'; -import { JwtAuthGuard } from 'src/modules/authentication/guards/jwt-auth.guard'; import { EmployeeEntity } from '../dtos/swagger-entities/employees.entity'; @ApiTags('Employees') @ApiBearerAuth('access-token') -@UseGuards(JwtAuthGuard) +// @UseGuards() @Controller('employees') export class EmployeesController { constructor(private readonly employeesService: EmployeesService) {} diff --git a/src/modules/expenses/controllers/expenses.controller.ts b/src/modules/expenses/controllers/expenses.controller.ts index 91e5b93..33d7b72 100644 --- a/src/modules/expenses/controllers/expenses.controller.ts +++ b/src/modules/expenses/controllers/expenses.controller.ts @@ -6,12 +6,11 @@ import { Roles as RoleEnum } from '.prisma/client'; import { UpdateExpenseDto } from "../dtos/update-expense"; import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; import { RolesAllowed } from "src/common/decorators/roles.decorators"; -import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; import { ExpenseEntity } from "../dtos/swagger-entities/expenses.entity"; @ApiTags('Expenses') @ApiBearerAuth('access-token') -@UseGuards(JwtAuthGuard) +// @UseGuards() @Controller('Expenses') export class ExpensesController { constructor(private readonly expensesService: ExpensesService) {} diff --git a/src/modules/leave-requests/controllers/leave-requests.controller.ts b/src/modules/leave-requests/controllers/leave-requests.controller.ts index 9a27b4b..7f4163f 100644 --- a/src/modules/leave-requests/controllers/leave-requests.controller.ts +++ b/src/modules/leave-requests/controllers/leave-requests.controller.ts @@ -6,12 +6,11 @@ import { UpdateLeaveRequestsDto } from "../dtos/update-leave-requests.dto"; import { RolesAllowed } from "src/common/decorators/roles.decorators"; import { Roles as RoleEnum } from '.prisma/client'; import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; -import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; import { LeaveRequestEntity } from "../dtos/swagger-entities/leave-requests.entity"; @ApiTags('Leave Requests') @ApiBearerAuth('access-token') -@UseGuards(JwtAuthGuard) +// @UseGuards() @Controller('leave-requests') export class LeaveRequestController { constructor(private readonly leaveRequetsService: LeaveRequestsService){} diff --git a/src/modules/oauth-sessions/controllers/oauth-sessions.controller.ts b/src/modules/oauth-sessions/controllers/oauth-sessions.controller.ts index 08d30d5..42890c1 100644 --- a/src/modules/oauth-sessions/controllers/oauth-sessions.controller.ts +++ b/src/modules/oauth-sessions/controllers/oauth-sessions.controller.ts @@ -3,7 +3,6 @@ import { OAuthSessions } from '@prisma/client'; import { RolesAllowed } from "src/common/decorators/roles.decorators"; import { Roles as RoleEnum } from '.prisma/client'; import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; -import { JwtAuthGuard } from 'src/modules/authentication/guards/jwt-auth.guard'; import { CreateOauthSessionDto } from '../dtos/create-oauth-sessions.dto'; import { OauthSessionsService } from '../services/oauth-sessions.service'; import { OAuthSessionEntity } from '../dtos/swagger-entities/oauth-sessions.entity'; @@ -11,7 +10,7 @@ import { UpdateOauthSessionDto } from '../dtos/update-oauth-sessions.dto'; @ApiTags('OAuth Sessions') @ApiBearerAuth('sessions') -@UseGuards(JwtAuthGuard) +//@UseGuards(JwtAuthGuard) @Controller('oauth-sessions') export class OauthSessionsController { constructor(private readonly oauthSessionsService: OauthSessionsService){} diff --git a/src/modules/shifts/controllers/shifts.controller.ts b/src/modules/shifts/controllers/shifts.controller.ts index c7ed0ca..f3a0704 100644 --- a/src/modules/shifts/controllers/shifts.controller.ts +++ b/src/modules/shifts/controllers/shifts.controller.ts @@ -6,12 +6,11 @@ import { UpdateShiftsDto } from "../dtos/update-shifts.dto"; import { RolesAllowed } from "src/common/decorators/roles.decorators"; import { Roles as RoleEnum } from '.prisma/client'; import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; -import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; import { ShiftEntity } from "../dtos/swagger-entities/shift.entity"; @ApiTags('Shifts') @ApiBearerAuth('access-token') -@UseGuards(JwtAuthGuard) +// @UseGuards() @Controller('shifts') export class ShiftsController { constructor(private readonly shiftsService: ShiftsService){} diff --git a/src/modules/timesheets/controllers/timesheets.controller.ts b/src/modules/timesheets/controllers/timesheets.controller.ts index e90e08f..7a1bfa2 100644 --- a/src/modules/timesheets/controllers/timesheets.controller.ts +++ b/src/modules/timesheets/controllers/timesheets.controller.ts @@ -6,12 +6,11 @@ import { UpdateTimesheetDto } from '../dtos/update-timesheet.dto'; import { RolesAllowed } from "src/common/decorators/roles.decorators"; import { Roles as RoleEnum } from '.prisma/client'; import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; -import { JwtAuthGuard } from 'src/modules/authentication/guards/jwt-auth.guard'; import { TimesheetEntity } from '../dtos/swagger-entities/timesheet.entity'; @ApiTags('Timesheets') @ApiBearerAuth('access-token') -@UseGuards(JwtAuthGuard) +// @UseGuards() @Controller('timesheets') export class TimesheetsController { constructor(private readonly timesheetsService: TimesheetsService) {}