nginx和nestjs身份验证部分之间的错误



我尝试使用带有Nginx反向代理的NestJS后端。我已经在NestJS后端编码了一个身份验证部分。

我的问题是,当我在本地模式下使用前端/后端时,一切都很好。当我通过Nginx使用它时,我总是检索到401错误。我认为这是由于NestJS 中的LocalStrategy

这是local.strategy.ts文件中的部分

import { Strategy } from 'passport-local';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { AuthService } from '../auth.service';
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
constructor(private authService: AuthService) {
super({
usernameField: 'userLogin',
passwordField: 'userPassword',
});
}
async validate(userLogin: string, userPassword: string): Promise<any> {
const user = await this.authService.validateUser(userLogin, userPassword);
if (!user) {
throw new UnauthorizedException();
}
return user;
}
}

这是app.controller.ts文件中的部分

@Public()
@UseGuards(LocalAuthGuard)
@Post('auth/login')
async login(@Request() req) {
return this.authService.login(req.user);
}

但我不知道如何改变它。如果有人有一个榜样,那就太棒了。提前谢谢。

我已经在服务器上本地测试了curl(没有nginx(。我看到了我的错误(mysql访问以测试用户(,这不是由于nginx配置造成的。

相关内容

最新更新