Session Variables?

How can I set a session variable for a logged in user?

Specifically, I have a user that can belong to several accounts. They need to be able to select which account they want to interact as when they are using the front end, and then change that as they are using it.

Hey @kevinwasie . I am not sure if I understand you, because I know you are very proficient with WeWeb and my answer is pretty straightforward. I have something like this, where one user might belong to multiple “hubs”, and can switch between them by selecting a different hub from a dropdown menu in the nav bar. The “Current Hub” is a variable that changes upon selection of a new hub. All relevant data are then filtered by the “Current Hub” variable, so they are only seeing the data for that hub.

Does that sound like what you are trying to do?

Hahah I appreciate the vote of proficiency… I just guess most of the time until it works lol…

I am trying to make it so that the variable carries over from page to page, and stays as it is until they logout, or they change it.

So, if they are on one page, and they select that they want to utilize their “foo hub”, then when they go to the next page, that variable is still set to “foo hub”

Doesnt the hub change every time they change pages in your scenario?

Oh, so for that, I toggle on the “Save in Local Storage” option. Have you tried that?

1 Like

Awesome! I did not know what that toggle did. Thank you!

1 Like

Wait. If a user logs out, does that variable change? If not, you could have someone on a public computer have an old variable in there, unless it’s cleared at every login/logout.

Yes, I have it reset at login and logout


I’m also curious about this.

If a user does not explicitly log out, won’t the local variable will still be present (as it’s in local storage, which is saved across sessions)?

I am trying to make it so that the variable carries over from page to page, and stays as it is until they logout, or they change it.

I’m still new to WeWeb, so forgive the naivety here—aren’t regular variables session variables that persist across pages? Ie, they’re stored in sessionStorage)? Or are the regular WeWeb variables only page-level variables?

Hey @caffeinatedwes,
I think this topic was created before we moved to Single Page Application. Now that we are navigating inside the SPA, rather than reload the page each time, the variable are persisted between page (but will be loose on refresh).
Store in localstorage is used if you want to persist the information between session (page refresh for example).

1 Like

Ahh, I see. Thank you, @aurelie!

Hi @aurelie, I wanted to bring up what you said here following the release of the new updates (which I’m absolutely PUMPED about).

As I’ve understood…

  • When navigating inside the SPA, variables persists (as you mention).
  • Variables only reset when refreshing the page.

With both of those things mentioned, how does the new “save variable when navigating between pages” feature work? How does it differ between a regular variable if regular variables already persist between pages?

Hi @caffeinatedwes the behavior you describe is when the toggle “Persist between navigation” is on.

  • Newly created variable will have this behavior set to true by defaut, but can be opt out
  • For backward compatibility, previously created variable will have this parameter set to false. You can enable it if you want
1 Like

Great, thank you for the clarity!