nestjs / passport

Passport module for Nest framework (node.js) 🔑

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AuthGuard always create session even if options.session = false

wguerram opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I'm using express session and redis, I don't want to create a session when executing oauth2-client-password, so I'm passing session: false in the constructor but the session is always created. Do I have to do somethin else to avoid the session being created?

`
@Injectable()
export class ClientPasswordAuthGuard extends AuthGuard([
'oauth2-client-password',
]) {
constructor() {
super({ session: false });
}

async canActivate(context: ExecutionContext): Promise {
const result = (await super.canActivate(context)) as boolean;
await super.logIn(context.switchToHttp().getRequest());
return result;
}
}
`

Not sure if is related to #658

Minimum reproduction code

https://github.com/jmcdo29/dev.to/tree/main/blog-posts/nestjs-passport-sessions

Steps to reproduce

I follow this guide with the difference I'm adding an additional guard and strategy.

https://dev.to/nestjs/setting-up-sessions-with-nestjs-passport-and-redis-210
https://github.com/jmcdo29/dev.to/tree/main/blog-posts/nestjs-passport-sessions

Expected behavior

Session should not be created.

Package version

8.0.1

Passport version

0.5.0

NestJS version

8.0.8

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

How can I override the call to login in the AuthGuard to pass options?

According to this options has no effect when sent to the authenticate function.
https://stackoverflow.com/questions/25171231/passportjs-custom-callback-and-set-session-to-false

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.