해결된 질문
작성
·
138
0
안녕하세요 제로초님 LocalGuard에서 can으로 넘어가지가 않아서 질문드립니다.
import { ExecutionContext, Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
@Injectable()
export class LocalAuthGuard extends AuthGuard('local') {
async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest();
console.log('LocalAuthGuard canActivate - request.body:', request); // 추가 로그
console.log('LocalAuthGuard canActivate - before super.canActivate'); // 추가 로그
let can = await super.canActivate(context);
console.log(can);
if (can) {
const request = context.switchToHttp().getRequest();
console.log('login for cookie');
console.log('request.user:', request.user); // 추가 로그
await super.logIn(request);
}
return true;
}
}
여기서 보면 requsetbody에는 request.body: { teacherId: 'hee', password: '12534' } 이렇게 제가 설정한값이 들어가고
UnauthorizedException: Unauthorized
at LocalAuthGuard.handleRequest (/Users/mac/Desktop/sideProject/piano-erp-back/node_modules/@nestjs/passport/dist/auth.guard.js:60:30)
at /Users/mac/Desktop/sideProject/piano-erp-back/node_modules/@nestjs/passport/dist/auth.guard.js:44:124
at /Users/mac/Desktop/sideProject/piano-erp-back/node_modules/@nestjs/passport/dist/auth.guard.js:83:24
at allFailed (/Users/mac/Desktop/sideProject/piano-erp-back/node_modules/passport/lib/middleware/authenticate.js:110:18)
at attempt (/Users/mac/Desktop/sideProject/piano-erp-back/node_modules/passport/lib/middleware/authenticate.js:183:28)
at strategy.fail (/Users/mac/Desktop/sideProject/piano-erp-back/node_modules/passport/lib/middleware/authenticate.js:314:9)
at Strategy.authenticate (/Users/mac/Desktop/sideProject/piano-erp-back/node_modules/passport-local/lib/strategy.js:75:17)
at attempt (/Users/mac/Desktop/sideProject/piano-erp-back/node_modules/passport/lib/middleware/authenticate.js:378:16)
at authenticate (/Users/mac/Desktop/sideProject/piano-erp-back/node_modules/passport/lib/middleware/authenticate.js:379:7)
at /Users/mac/Desktop/sideProject/piano-erp-back/node_modules/@nestjs/passport/dist/auth.guard.js:88:3 {
response: { message: 'Unauthorized', statusCode: 401 },
status: 401,
options: {}
}
undefined
teacher.decorator.ts undefined
이렇게 에러가나는데 원인은 잘모르겠습니다. 혹시 어떤부분을 살펴봐야할까요? 추가로 저기이외에 strategy쪽에는 console찍은게 아에 안들어옵니다.