Loading backend/src/shared/service/auth.module.ts 0 → 100644 +11 −0 Original line number Diff line number Diff line import { Module } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { AuthService } from './auth.service'; @Module({ controllers: [], providers: [JwtService, AuthService], imports: [], exports: [AuthService], }) export class AuthModule {} backend/src/shared/service/auth.service.ts 0 → 100644 +18 −0 Original line number Diff line number Diff line import { Injectable, UnauthorizedException } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { JwtConstants } from 'src/constants/jwt.constants'; import { PayloadJwtDto } from 'src/shared/dto/payload-jwt.dto'; @Injectable() export class AuthService { constructor(private jwtService: JwtService) {} async validateToken(token: string): Promise<string | null> { try { const payload: PayloadJwtDto = await this.jwtService.verify(token, { secret: JwtConstants.SECRET }); return payload.role; } catch (error) { throw new UnauthorizedException('Invalid token'); } } } Loading
backend/src/shared/service/auth.module.ts 0 → 100644 +11 −0 Original line number Diff line number Diff line import { Module } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { AuthService } from './auth.service'; @Module({ controllers: [], providers: [JwtService, AuthService], imports: [], exports: [AuthService], }) export class AuthModule {}
backend/src/shared/service/auth.service.ts 0 → 100644 +18 −0 Original line number Diff line number Diff line import { Injectable, UnauthorizedException } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { JwtConstants } from 'src/constants/jwt.constants'; import { PayloadJwtDto } from 'src/shared/dto/payload-jwt.dto'; @Injectable() export class AuthService { constructor(private jwtService: JwtService) {} async validateToken(token: string): Promise<string | null> { try { const payload: PayloadJwtDto = await this.jwtService.verify(token, { secret: JwtConstants.SECRET }); return payload.role; } catch (error) { throw new UnauthorizedException('Invalid token'); } } }