# Session Decorator operation input
Module | import { Session } from "@tsed/common" |
---|---|
Source | /packages/common/src/mvc/decorators/params/session.ts |
# Overview
function Session(expression: string): ParameterDecorator;
export function Session(options: IParamOptions<any>): ParameterDecorator;
export function Session(): ParameterDecorator;
Param | Type | Description |
---|---|---|
expression | string | The path of the property to get. |
# Description
Session return the value from request.session object.
# Example
@Controller('/')
class MyCtrl {
@Post('/')
create(@Session() session: Express.Session) {
console.log('Entire session', session);
}
@Post('/')
create(@Session('id') id: string) {
console.log('ID', id);
}
@Post('/') // Example to deserialize use from session
create(@Session({expression: 'user', useConverter: true}) user: User) {
console.log('user', user);
console.log('instanceOf user', user instanceof User);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
For more information on deserialization see converters page.
- Session & cookies
- Passport.js
- TypeORM
- Mongoose
- GraphQL
- Socket.io
- Swagger
- AJV
- Multer
- Serve static files
- Templating
- Throw HTTP Exceptions
- Customize 404
- AWS
- Jest
- Seq
- Controllers
- Providers
- Model
- Converters
- Middlewares
- Pipes
- Interceptors
- Authentication
- Hooks
- Injection scopes
- Custom providers
- Custom endpoint decorator
- Testing