#Calling app.use before setting up the routes

13 messages · Page 1 of 1 (latest)

opal goblet
#

When I try to use session.destroy() I get the error:

[Nest] 73846  - 02/11/2024, 9:42:58 PM   ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'req')
TypeError: Cannot read properties of undefined (reading 'req')
    at destroy (<>/extremepriv/privateserver/node_modules/express-session/session/session.js:110:15)
    at node:internal/util:442:7
    at new Promise (<anonymous>)
    at destroy (node:internal/util:428:12)
    at AppController.root (<>/extremepriv/privateserver/src/app.controller.ts:13:41)

The lines that are causing an error are commented out in this file, I would like to uncomment to prevent session reuse:
https://github.com/jido/extremepriv/blob/main/privateserver/src/app.controller.ts

This solution suggests to call app.use(session) before setting up the routes, how is that done in NestJS?

https://stackoverflow.com/questions/41052799/typeerror-cannot-read-property-regenerate-of-undefined

GitHub

Extreme privacy demo page. Contribute to jido/extremepriv development by creating an account on GitHub.

rancid sigil
#

Ah. you are using app.use. The invocation before setting up routes happens automatically under the hood in Nest.

#

What is the purpose of using promisify?

opal goblet
#

Does it? Thank you!

#

I will try without promisify, that was to simplify my code using async.

#

I will need to return a promise anyway right?

rancid sigil
#

I don't believe the session methods are async to begin with. @opal goblet

opal goblet
#

they are, they require a callback

rancid sigil
#

@opal goblet - Yeah, well. Just because a function has a callback as an argument, doesn't make it asynchronous.

rancid sigil
opal goblet
#

Hi, did you remove the code? I realised what you mean with callbacks but I can't get my code to work.

opal goblet