flexdash / node-red-flexdash

Node-RED server integration for FlexDash
MIT License
10 stars 3 forks source link

Unable to use Flexdash when adminAuth configured for OAuth #12

Closed knolleary closed 1 year ago

knolleary commented 1 year ago

When adminAuth is configured for oauth access, opening the flexdash page results in a fatal error:

TypeError: req.session.touch is not a function

I have tracked down the root cause and will be raising a PR shortly with a proposed fix/workaround in Flexdash.

In summary, with adminAuth setup, Node-RED sets req.session to an instance of express-session. This includes a hook once the request is completed to trigger a refresh of the cookie (by calling req.session.touch()).

Flexdash uses cookie-session (https://github.com/flexdash/node-red-flexdash/blob/main/flexdash-dashboard.js#L278)

This sets req.session to a new session object with every request that hits the flexdash express app. In doing so it overwrites the existing req.session value with a different session implementation that doesn't include touch. So when express-session runs its code to refresh the cookie, req.session is no longer the one it expected and you get the reported error.

There are a number of long-open issues around supporting multiple session objects in express to help support this type of application co-existence - unfortunately they have not got anywhere with proposed PRs unmerged.

Having explored various options in both Node-RED and flexdash, I think the only practical solution is to add some conditional logic around where flexdash sets up req.session to only do so if no such object already exists. I have verified that works locally for the simple case of accessing the dashboard, but not done an exhaustive test of flexdash's cookie handling to ensure it all hangs together as expected.

Originally reported here: https://github.com/flowforge/flowforge/issues/1778