-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
passport 관련 질문드립니다
22.12.15 09:47 작성 조회수 139
0
controller
@ApiBody({
schema: {
properties: {
email: { type: 'string' },
password: { type: 'string' }
}
}
})
@UseGuards(LocalAuthGuard)
@Post('login')
async login(@Req() req) {
console.log('user controller');
return this.authService.login(req.user);
}
local.strategy
constructor(private authService: AuthService) {
super();
}
async validate(email: string, password: string): Promise<any> {
console.log('local strategy');
console.log(`${email} , ${password}`);
const user = await this.authService.validateUser(email, password);
if (!user) {
throw new UnauthorizedException();
}
return user;
}
local-auth.guard
async canActivate(context: ExecutionContext): Promise<boolean> {
console.log(context);
const can = await super.canActivate(context);
console.log('can', can);
if (can) {
const request = context.switchToHttp().getRequest();
console.log('login for cookie');
await super.logIn(request);
}
return true;
}
이렇게 구성되어있는데
canActivate에서 401 에러가 나는데 이유를 잘모르겠습니다.
답변을 작성해보세요.
0
조현영
지식공유자2022.12.15
로그인 시 에러가 나는 건가요? 아니면 로그인 후에 다른 요청에서 에러가 나는 건가요?
validateUser가 통과하는지 console.log(user)도 해보세요.
답변 1