我请求的token放在header里面,我想在nestjs的守卫代码里获得header里面的token,但是不知道怎么在守卫获得header对象
代码如下,有人知道吗?
import {
CanActivate,
ExecutionContext,
HttpException,
HttpStatus,
Injectable,
} from '@nestjs/common';
import { Observable } from 'rxjs';
const whiteList = ['/admin/login'];
@Injectable()
export class AuthGuard implements CanActivate {
canActivate(
context: ExecutionContext,
): boolean | Promise<boolean> | Observable<boolean> {
const request = context.switchToHttp().getRequest();
console.log(request.user);
const url = request.route.path;
// console.log(request);
//白名单的直接返回
if (whiteList.includes(url)) {
return true;
}
// if (!header.token) {
// //throw new HttpException('用户未登录', HttpStatus.BAD_REQUEST);
// }
return true;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…