The problem with session variables

Wappler 7.9.4, nodejs, postgresql

In Glogal i setup session variable glob_ses. Also i include library server connect. And i have Security identity step.

in library i setup new session variable lib_ses

for test i have simple server action:

if i run it first time i see only one variable:

if i run it the second time i see TWO variables:

Why???
BUT if i disable Security Identity step I get both variables on the first run!!!

But i can’t do this situation again in new clean project :exploding_head:

It turns out that, in my case, the Security Identity in the Global scope affects the variables in the $_SESSION that are set in the library on the first run (during session initialization).

I don't think this is how it's supposed to work. Any ideas why this is happening?

It seems the library isn't the issue; what matters is whether the session variable is assigned before or after Security Identity.
In this case, neither variable appears on the first run, but both are visible on subsequent runs.

I changed the storage location for session variables to the database. This way, I can track their status. As a result, I see that after the first run, all variables are added to the database, but they don’t appear in the output—that is, they don’t exist during the first run, even though they’re already in the database. When I run it again, nothing changes in the database, and the variables are now displayed. So far, I see that the problem lies with Security Identity, which for some reason affects session variables in this way.

After running various tests, I found that Security Identity affects session variables when a session is first started only if a user is logged in. If the user is not logged in, everything works as expected. Is there anything that can be done about this? @Teodor

I found the solution.

the file /lib/core/app.js need to little bit correct function:

    regenerateSessionId: function () {
    return new Promise((resolve, reject) => {
      // Save session data VALUES before regeneration (not just reference)
      const oldSessionData = {};
      for (let key in this.req.session) {
        if (key !== 'regenerate' && key !== 'cookie') {
          oldSessionData[key] = this.req.session[key];
        }
      }

      this.req.session.regenerate((err) => {
        if (err) return reject(err);

        // Restore session data from saved values
        for (let key in oldSessionData) {
          this.req.session[key] = oldSessionData[key];
        }

        // IMPORTANT: update Server Connect $_SESSION reference
        this.set('$_SESSION', this.req.session);

        resolve();
      });
    });
  },

This must be added:
// IMPORTANT: update Server Connect $_SESSION reference
this.set('$_SESSION', this.req.session);

and it seems the problem is going away :melting_face:

Please @Teodor include this in the update so the next one doesn't break my site :slight_smile:

What I like about Wappler is that all the code is available and not hidden, so you can understand and fix it—something you don't get with other no-code systems. (Even though Wappler isn't strictly no-code, it still has that advantage.)

Sorry for the late reaction. I've added the change for the next update.

Thank you very much! It's nice to know that I've been able to help the community, too.

Fixed in Wappler 7.9.6

I updated Wappler to 7.9.6, after which Wappler prompted me to update app.js—so I did. As a result, the file in my project reverted to its previous version. The session issue has not been fixed. :sob:

The server connect update was released as a beta update, the fix is included there, so make sure you switch to the beta extensions channel and update it.

I switched the update channel to beta, but the result is the same. Wappler suggested updating app.js, but after the update, it turns out to be the old version.