Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
Error between nginx and nestjs authentication part

I try to use a NestJS backend with a Nginx reverse proxy. I have coded an authentication part in my NestJS backend.

My problem is that when I used my frontend / backend in local mode, all is ok. When I use it through Nginx, I always retrieve a 401 error. I think it’s due to the LocalStrategy in NestJS

Here is the part in the local.strategy.ts file

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;
  }
}

Here is the part in the app.controller.ts file

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

But I don’t know how to change it. If somebody have an example it build be great. Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I've tested with curl locally on server (without nginx). I saw my error (mysql access to test the user), it was not due to nginx configuration.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda