Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!