# Session Decorator

Module
import { Session } from "@tsed/common"
Source/packages/common/src/mvc/decorators/params/session.ts

# Overview

function Session(expression: string): ParameterDecorator;
function Session(options: IParamOptions<any>): ParameterDecorator;
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

For more information on deserialization see converters page.