How to save session information to a file in "express-openid-connect"

I want to use “express-openid-connect” in my desktop application to perform Open ID Connect authentication.

In a desktop application, the session information disappears every time the server is restarted, so I want to use the “session-file-store” module to save the session information to a file and skip authentication without opening the browser on subsequent launches, as long as it is within TTL.

For this I wrote the following code.

const { app } = require('electron');
const session = require("express-session");
const FileStore = require("session-file-store")(session);

let filestore = new FileStore({
  path: `${app.getPath('userData')}/sessions`, 
  ttl: 30 * 24 * 60,
  secret: "APP_SECRET",
  fileExtension: ".bin"
});

let params = {
  authRequired: false,
  auth0Logout: true,
  issuerBaseURL: /* issuerBaseURL */,
  baseURL: /* callbackURL */,
  clientID: /* clientID */,
  secret: /* secret */,
  clientSecret: /* clientSecret */
  session: {
      store: filestore
  }
  authorizationParams: {
    response_type: "code",
  }
}
const app = express();
app.use(auth(params));
app.get('/' , (req , res)=>{
  if(req.oidc.isAuthenticated()){
    /* The code when the user is verified to be authenticated. */
  }
});
/* ... */

Although the authentication itself is performed correctly and the session data is saved to the location specified in the FileStore class, the file is not read before the execution of the req.oidc.isAuthenticated() method, and req.oidc.isAuthenticated() becomes false.

Also, when debugging the code in Visual Studio Code and checking the flow of the program, it does not appear that it calls the get() method of the session store before req.oidc.isAuthenticated(), and the file loading process does not seem to be performed.

It’s possible that it’s not an exact usage because I still don’t fully understand how session stores work, but I wonder if session stores aren’t meant to be used this way?

Also, how can I store credentials in a file and skip the authentication process when the TTL deadline is within and the authentication data is valid?

Posts I’ve checked elsewhere

My Environment

  • node-version:14.17.0
  • electron-version:14.2.9 <–As previously confirmed in the following issue, in the environment of Electron 19.0.5 and Node 16.14.2, express-openid-connect does not work, so the version of Electron has been lowered.