update
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
import { SetMetadata } from '@nestjs/common'
|
||||
|
||||
export const IS_PUBLIC_WITH_TOKEN_KEY = 'IS_PUBLIC_WITH_TOKEN_KEY'
|
||||
export const PublicWithToken = () => SetMetadata(IS_PUBLIC_WITH_TOKEN_KEY, true)
|
||||
@@ -10,6 +10,7 @@ import { Reflector } from '@nestjs/core'
|
||||
import { JwtService } from '@nestjs/jwt'
|
||||
import { Request as ExpressRequest } from 'express'
|
||||
import { IS_PUBLIC_KEY } from '../decorators/public.decorator'
|
||||
import { IS_PUBLIC_WITH_TOKEN_KEY } from '../decorators/withToken.decorator'
|
||||
import { ConsumerGuard } from './auth-consumer.guard'
|
||||
import { PosGuard } from './auth-pos.guard'
|
||||
|
||||
@@ -43,6 +44,14 @@ export class JwtAuthGuard implements CanActivate {
|
||||
|
||||
if (!token) throw new UnauthorizedException('Missing access token')
|
||||
|
||||
const isPublicWithToken = this.reflector.getAllAndOverride<boolean>(
|
||||
IS_PUBLIC_WITH_TOKEN_KEY,
|
||||
[context.getHandler(), context.getClass()],
|
||||
)
|
||||
if (isPublicWithToken) {
|
||||
return true
|
||||
}
|
||||
|
||||
try {
|
||||
this.jwt.verify(token, {
|
||||
secret: process.env.JWT_SECRET,
|
||||
|
||||
Reference in New Issue
Block a user