Git Product home page Git Product logo

Comments (3)

akumaaayush avatar akumaaayush commented on June 22, 2024 1

If you hover into the session from request object, you'll get:

This request's Session object. Even though this property isn't marked as optional, it won't exist until you use the express-session middleware Declaration merging can be used to add your own properties.

The default Session object isn't able to add out custom fields like UserId. My take was to do declaration merging by:
First, updating the tsconfig file to use the declaration i.e, adding up

  "typeRoots": [
    "./src/types", // for express.session declaration merging 
    "./node_modules/@types" 
  ]

And adding this in the types.ts:

import "express-session";

declare module 'express-session' {
    export interface Session {
        userId: number;
    }
}
export type myContext = {
    em: EntityManager<IDatabaseDriver<Connection>>;
    req: Request & { session: Session & Partial<SessionData> };
    res: Response;
}

Also, see check the secure property in the cookie property of app.use(session(...)). I had to set it to false to make the cookie work. Hope this helps.

from lireddit.

ryankert01 avatar ryankert01 commented on June 22, 2024

I first solve this problem with @akumaaayush's approach, and then, I found an issue that is all about this problem, so I came to share it.
#13

from lireddit.

dreeverl20 avatar dreeverl20 commented on June 22, 2024

@akumaaayush @ryankert01 thank you for your help but I have tried all this plus everything in #13 and I am still getting the same error.

from lireddit.

Related Issues (20)

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.