nestjs / passport

Passport module for Nest framework (node.js) 🔑
https://nestjs.com
MIT License
504 stars 117 forks source link

AuthGuard on Local Strategy return undefinded #1169

Closed PatrykKuniczak closed 1 year ago

PatrykKuniczak commented 1 year ago

Is there an existing issue for this?

Current behavior

@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
    constructor(private authService: AuthService) {
        super();
    }

    async validate(username: string, password: string) {
        username = username.replace(/\s/g, "").toLowerCase();
        const user = await this.authService.validateUser({username, password});

        if (!user) {
            throw new UnauthorizedException()
        }

        return user
    }
}

That's code it's very similiar to this from your docs.

And what the point, after last update

"@nestjs/passport": "9.0.1"

I have an Error in the console, after i throw any error from this authService or manually from this validate func.

Nest wrong handle throwed exeptions, i can throw ep.

        throw new BadGatewayException()

And i have still that error: image

My app work fine, but i have a info in the console.

That's work well on 9.0.0 version, only on the latest update this error occure.

Minimum reproduction code

Don't necessary in that case, code from docs it's the same

Steps to reproduce

No response

Expected behavior

Don't console.error(undefined) from AuthGuard :)

Package version

9.0.1

Passport version

0.6.0

NestJS version

9.3.5

Node.js version

19.6.0

In which operating systems have you tested?

Other

I using Windows 11, and WebStorm 2022.3.2

kamilmysliwiec commented 1 year ago

Fixed in the latest versions of @nestjs/passport & @nestjs/core