Commit 8d9179cf authored by Diego Iván's avatar Diego Iván
Browse files

corrigiendo error al obtener bearer token

parent 18790c50
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -11,12 +11,11 @@ export class AuthGuard implements CanActivate {
  ) {}
  async canActivate(context: ExecutionContext): Promise<boolean> {
    const requiredRole = this.reflector.get(Roles, context.getHandler());
    console.log(requiredRole);

    if (!requiredRole) return true;
    const request = context.switchToHttp().getRequest();
    const { authorization }: any = request.headers;
    let { authorization }: any = request.headers;
    if (!authorization) throw new UnauthorizedException('session expired! Please sign In');
    authorization = authorization.split(' ')[1];
    const role = await this.authService.validateToken(authorization);
    if (!requiredRole.includes(role)) throw new UnauthorizedException('Unauthorized access');
    return true;