Ok, here is what I’m trying to do with session:
As user first logs in, I’ll fetch user details and some access details from DB and then store it to session using wix session storage method. I store it to session, because for almost all pages, there are access checks and I need user details, if user makes any update or insert, so to avoid multiple calls to DB, I save it to session.
How I’m storing to session?
I’m calling a method which will first check if session has any value/data, if not then fetch the data from DB using currentuser.id. So, when I call these methods every-time in all different places in my app, it will first check if session has value if not then get it from DB. I did this to improve the performance of my web app.
Now here is what going wrong.
All my methods works fine, but as I noticed if one user (let’s say Patrick) logs out from the app (using wix member navbar), session will still holds all the data of Patrick who has already logged out, and when an another user (let’s say Mike) logs into the same computer and in the same browser. The app responds as if, it is Patrick, because session still holds Patrick’s information. Though Mike is logged in and session has values/data of Patrick my methods are not getting the data from DB, instead taking it from session.
How I tried to fix this?
First I thought I’ll try to somehow clear the session as user logs out, but unfortunately there is no option by which I can override or edit the code of logout button under “Wix Member NavBar”. So, I tried an another hack by using the onLogin() to clear the session, as every-time a new user or the same user logs into the system. Session.clear() is not doing its job, even though I’ve put this code in the Site code instead of page code, so no matter where user login their session will be cleared.
How do I know, session.clear() not working?
When I login as a different user in the same browser, I can clearly see the session still holds the previous user’s details instead of current logged in user. With the help of site monitor.