![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
nestjs-session
Advanced tools
Idiomatic Session Module for NestJS. Built on top of express-session😎
This module realise session with storing it's data in one of external stores and passing ID of session to client via Cookie
/Set-Cookie
headers.
If you want to store data directly in Cookie
, you can look at nestjs-cookie-session.
Register module:
// app.module.ts
import { Module } from '@nestjs/common';
import { NestSessionOptions, SessionModule } from 'nestjs-session';
import { ViewsController } from './views.controller';
@Module({
imports: [
// sync params:
SessionModule.forRoot({
session: { secret: 'keyboard cat' },
}),
// or async:
SessionModule.forRootAsync({
imports: [ConfigModule],
inject: [Config],
// TIP: to get autocomplete in return object
// add `NestSessionOptions` here ↓↓↓
useFactory: async (config: Config): Promise<NestSessionOptions> => {
return {
session: { secret: config.secret },
};
},
}),
],
controllers: [ViewsController],
})
export class AppModule {}
In controllers use NestJS built-in Session
decorator:
// views.controller.ts
import { Controller, Get, Session } from '@nestjs/common';
@Controller('views')
export class ViewsController {
@Get()
getViews(@Session() session: { views?: number }) {
session.views = (session.views || 0) + 1;
return session.views;
}
}
BE AWARE THAT THIS EXAMPLE IS NOT FOR PRODUCTION! IT USES IN-MEMORY STORE, SO YOUR DATA WILL BE LOST ON RESTART. USE OTHER STORES
See redis-store example in examples
folder.
To run examples:
git clone https://github.com/iamolegga/nestjs-session.git
cd nestjs-session
npm i
cd examples/in-memory # or `cd examples/in-memory-async` or `cd examples/redis-store`
npm i
npm start
For redis exmaple you should start redis on localhost:6379.
If you have docker you can start redis image by npm run redis
.
npm i nestjs-session
or
yarn add nestjs-session
SessionModule
class has two static methods, that returns DynamicModule
, that you need to import:
SessionModule.forRoot
for sync configuration without dependenciesSessionModule.forRootAsync
for sync/async configuration with dependenciesAccept NestSessionOptions
. Returns NestJS DynamicModule
for import.
Accept NestSessionAsyncOptions
. Returns NestJS DynamicModule
for import.
NestSessionOptions
is interface of all options, has next properties:
session
- required - express-session options.forRoutes
- optional - same as NestJS buil-in MiddlewareConfigProxy['forRoutes']
See exmaples in official docs. Specify routes, that should have access to session. If forRoutes
and exclude
will not be set, then sessions will be set to all routes.exclude
- optional - same as NestJS buil-in MiddlewareConfigProxy['exclude']
See exmaples in official docs. Specify routes, that should not have access to session. If forRoutes
and exclude
will not be set, then sessions will be set to all routes.retries
- optional - number
- by default if your session store lost connection to database it will return session as undefined
, and no errors will be thrown, and then you need to check session in controller. But you can set this property how many times it should retry to get session, and on fail InternalServerErrorException
will be thrown. If you don't want retires, but just want to InternalServerErrorException
to be throw, then set to 0
. Set this option, if you dont't want manualy check session inside controllers.retriesStrategy
- optional - (attempt: number) => number
- function that returns number of ms to wait between next attempt. Not calls on first attempt.NestSessionAsyncOptions
is interface of options to create session module, that depends on other modules, has next properties:
imports
- optional - modules, that session module depends on. See official docs.inject
- optional - providers from imports
-property modules, that will be passed as arguments to useFactory
method.useFactory
- required - method, that returns NestSessionOptions
.Also if you are into NestJS ecosystem you may be interested in one of my other libs:
Platform agnostic logger for NestJS based on pino with request context in every log
Idiomatic session module for NestJS. Built on top of express-session
Idiomatic cookie session module for NestJS. Built on top of cookie-session
Type safe roles guard and decorator made easy
Distributed consistent flexible NestJS rate limiter based on Redis
create-nestjs-middleware-module
Create simple idiomatic NestJS module based on Express/Fastify middleware in just a few lines of code with routing out of the box
Declarative configuration of NestJS middleware order
FAQs
Idiomatic NestJS module for session
The npm package nestjs-session receives a total of 4,645 weekly downloads. As such, nestjs-session popularity was classified as popular.
We found that nestjs-session demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.