Include the passport middlewares initialization in the module
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
With the current version, it seems, to use passport with cookies sessions, we have to declare its middlewares manually in main.js
, like :
app.use(session({
secret: 'a secret',
name: 'abcd',
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
This approach prevents me to use Nest injection, so it prevents me to use my ConfigurationModule & TypeORMModule for example to configure the session store.
Expected behavior
So I would like this nestjs/passport module register passport.initialize()
and passport.session()
automatically.
I’ve tried, by “monkey-patching” the library to add this configure
implementation in PassportModule code :
configure(consumer) {
const DEFAULT_ROUTES = [{ path: '*', method: common_1.RequestMethod.ALL }];
const middlewares = [
passport.initialize(),
passport.session(),
]
consumer
.apply(...middlewares)
.forRoutes(...DEFAULT_ROUTES)
}
But maybe it should be “configurable”, maybe it could depend on the session
options flag.
But I don’t know how to implement such a case in practice. I wonder if we have to implement forRoot / forRootAsync on PassportModule to do it this way ?
Minimal reproduction of the problem with instructions
The following repository provide a good base to reproduce the case : https://github.com/Nabellaleen/hello-graphql-session-nestjs
What is the motivation / use case for changing the behavior?
In practice, this change is motivated by this discussion : https://github.com/iamolegga/nestjs-session/issues/181
Environment
- @nestjs/common: 7.0.5
For Tooling issues:
- Node version: v10.15.3
- Platform: Linux
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
at least we should document it. the current document about @nestjs/passport miss quite a lot of important but very detailed features and considering only stateless backend using jwt
I don’t talk about “handling
express-session
” and so to “have additional modules” for each strategyI talk about handling the core passport feature of “session” This “core” is probably used by more than one strategy And “session” should be easy to do, because so many people are just putting their JWTs in LocalStorage to reinvent the wheel