Giter VIP home page Giter VIP logo

nestjs-session's Introduction

Here is a list of my own open source projects:

NestJS

nestjs-pino

GitHub stars npm

Platform agnostic logger for NestJS based on pino with request context in every log.


nestjs-session

GitHub stars npm

Idiomatic session module for NestJS. Built on top of express-session.


nestjs-cookie-session

GitHub stars npm

Idiomatic cookie session module for NestJS. Built on top of cookie-session.


nestjs-roles

GitHub stars npm

Type safe roles guard and decorator made easy.


nestjs-injectable

GitHub stars npm

@Injectable() on steroids that simplifies work with inversion of control in your hexagonal architecture.


nest-ratelimiter

GitHub stars npm

Distributed consistent flexible NestJS rate limiter based on Redis.


create-nestjs-middleware-module

GitHub stars npm

Create a simple idiomatic NestJS module based on Express/Fastify middleware in just a few lines of code with routing out of the box.


nestjs-configure-after

GitHub stars npm

Declarative configuration of NestJS middleware order.


nestjs-saga

GitHub stars npm

Basic implementation of saga pattern for NestJS (do not confuse it with the built-in sagas).


nestjs-gcp-pubsub

GitHub stars npm

The most basic and unopinionated implementation of GCP PubSub transport for NestJS microservices.


nest-nsq-transport

GitHub stars npm

The most basic and unopinionated implementation of NSQ transport for NestJS microservices.

React Native

react-native-launch-arguments

GitHub stars npm

Get launch arguments for testing with Detox and Appium.

Go

enviper

GitHub stars

Consider environment variables while unmarshaling viper's config.


rebus

GitHub stars

Type-safe bus generator for go.


ratelimiter

GitHub stars

Rate limiter with sliding window algorithm implementation.

nestjs-session's People

Contributors

actions-user avatar dependabot-preview[bot] avatar dependabot[bot] avatar github-actions[bot] avatar iamolegga avatar mergify[bot] avatar ovr avatar quantumsheep avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nestjs-session's Issues

[QUESTION] How to set up nestjs-session with session-file-store

[x] I've read the docs

[x] I've read the docs of express-session

[x] I couldn't find the same question

Question
I am re-writing a plain Express app into a more structured NestJS app and I am having trouble dealing with sessions. Here is my setup.

main.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap(): Promise<void> {
  const app = await NestFactory.create(AppModule);

  const port = process.env.PORT;
  await app.listen(port);
}

bootstrap().catch((err: unknown) => {
  console.error(err);
});

app.module.ts

import { Module } from '@nestjs/common';
import * as session from 'express-session';
import { SessionModule } from 'nestjs-session';
import * as sessionFileStore from 'session-file-store';

import { AppController } from './app.controller';
import { AppLoggerModule } from './app-logger/app-logger.module';
import { AuthModule } from './auth/auth.module';

const sessionTimeToLiveInSeconds = 60 * 60 * 12; //43200 seconds = 12 days
const cookieMaxAgeInMilliseconds = 1000 * 60 * 60 * 24 * 7; //604800000 ms = 1 week
const FileStore = sessionFileStore(session);

@Module({
  imports: [
    SessionModule.forRoot({
      session: {
        secret: process.env.secret,
        resave: true,
        store: new FileStore({ path: './sessions', ttl: sessionTimeToLiveInSeconds }),
        saveUninitialized: false,
        cookie: {
          secure: false,
          httpOnly: false,
          sameSite: false,
          maxAge: cookieMaxAgeInMilliseconds,
        },
      },
    }),
    AuthModule,
    AppLoggerModule,
  ],
  controllers: [AppController],
  providers: [],
})
export class AppModule {}

And when I start the NestJS server it's all good, but I make a simple GET request for something that just returns a "Hello World" string which works but I get the following error in my console 5 times

[session-file-store] will retry, error on last attempt: Error: ENOENT: no such file or directory, open 'C:\Users\<my-repo>\sessions\jm22rlgjMBLrxR0H3SUayhAlPEXI6oZY.json'

And of course no session JSON files are created either. Please help, I'm a little new at this but I feel like I'm doing everything correctly here and my system just can't write files to that folder for some reason. The sessions folder does exist, and it has the correct read/write permission on it.

Please mention other relevant information such as Node.js version and Operating System.

NestJS Version : 10.3.8
OS Version     : Windows 10.0.19045
NodeJS Version : v20.10.0
NPM Version    : 10.2.3

express-session: 1.18.0
nestjs-session : 3.0.1   

[BUG] Depracation warnings

After integrating this into my Nest project we ran into these warnings. Could you resolve them please?

Fri, 18 Dec 2020 04:00:02 GMT express-session deprecated undefined resave option; provide resave option at node_modules/nestjs-session/dist/index.js:8:22

Fri, 18 Dec 2020 04:00:02 GMT express-session deprecated undefined saveUninitialized option; provide saveUninitialized option at node_modules/nestjs-session/dist/index.js:8:22

[QUESTION] How to get session in custom middleware?

I have my own middlewares and need to get session from there, from req.session, but it is undefined.

But it is available in nest controllers via @Session() session or @Req() req.session...

How to get session in middleware?

[BUG] Middleware not called while using nestjs-session with @nestjs/graphql

What is the current behavior?

I don't succeed to make this package work with @nestjs/graphql.
When I call a REST route, it's working well, and the session(req, res, next) middleware (from express-session) is well called.
But when I call the GraphQL entrypoint, the middleware is not called at all.

I've digged deep in nestjs source-code, but I don't know really where to look.

Even with a forRoutes: [{ path: '/*', method: RequestMethod.ALL }], this change nothing.

What is the expected behavior?

In practice, the consequences are that no cookie is defined in the GraphQL response, and so, the sessions don't work.

Please mention other relevant information such as Node.js version and Operating System.

[BUG] misconfigured csrf

What is the current behavior?

If using this module alongside with csurf then got an error misconfigured csrf

Please provide the steps to reproduce.

  1. create new nest project.
  2. add SessionModule.forRoot({ session: { secret: 'secret' } }) to app.module.ts.
  3. add app.use(csurf()) to main.ts.
  4. create a controller to handle request.
  5. got the error misconfigured csrf.

What is the expected behavior?

Do not get this error.

Please mention other relevant information such as Node.js version and Operating System.

- Nest version: 7.2.0
- Node version: v12.16.3
- Platform: Windows

[BUG] Not working with @nestjs/graphql

What is the current behavior?

Using @Session in a resolver dosen't work, and session is null.

Please provide the steps to reproduce.

Install Nest with graphql, and install this. Then, in your resolver have a @Session parameter and see what it is. It will be null.

What is the expected behavior?
It isn't null.

Please mention other relevant information such as Node.js version and Operating System.
Node 11.15.0, session configuration:

SessionModule.forRoot({
  session: {
    secret: 'temp',
    store: new RedisStore({ client: RedisConnection }),
    resave: false,
    saveUninitialized: true
  }
});

In my resolver:

  @Mutation(() => User)
  async register(
    @Session() session: SessionType
  ) {
    .....

    session.user = user.id; // TypeError: Cannot set property 'user' of null
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.