Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

277
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda