Hi,
I don't understand how to inject sessions
https://github.com/pleerock/routing-controllers#inject-session-object
I've installed express-session.
import { Session } from "routing-controllers";
//import * from "express-session";
var session = require('express-session');
@Post("/login/")
loginUser(@Session() session: Express.Session, @Body() user: User) {
}
How to find such a "Express.Session" type ? How and what to import ?
adding @19majkel94
How to find such a "Express.Session" type ? How and what to import ?
npm i -s @types/express-session
Express is a global namespace so no imports are needed.
You may also need interface merging to declare properties that you want to store in session:
declare namespace Express {
export interface Session {
user: any;
}
}
Also, you need to configure the express-session middleware - this might help.
Thank you very much @19majkel94, it works fine!
I also need to use/inject in my controllers:
Just use the @Req() decorator to inject the whole Request object like in normal express handler. Or write custom decorator that will extract and inject that for you 馃槈
I think this can be closed