17 lines
452 B
TypeScript
17 lines
452 B
TypeScript
import { Injectable, ExecutionContext, UnauthorizedException } from '@nestjs/common';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
|
|
@Injectable()
|
|
export class JwtAuthGuard extends AuthGuard('jwt') {
|
|
canActivate(context: ExecutionContext) {
|
|
return super.canActivate(context);
|
|
}
|
|
|
|
handleRequest(err: any, user: any, info: any) {
|
|
if (err || !user) {
|
|
throw err || new UnauthorizedException('请先登录');
|
|
}
|
|
return user;
|
|
}
|
|
}
|