When switching tab i get logged uit
When switching tab on my prod site i get logged out and have to log back in again. this happens every tab switch.
4 Replies
Hi @Sven. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
This issue you're experiencing is a known behavior in Wasp and is currently being addressed. The problem occurs due to how Wasp handles authentication tokens and responses across different tabs. Here's a breakdown of the situation:
1. The issue is related to how Wasp clears auth tokens on 401 responses. When you switch tabs, it's possible that one tab is making a request without an auth token, which then triggers a logout across all tabs. This is described in Github Issue #1227 (https://github.com/wasp-lang/wasp/issues/1227).
2. The behavior you're seeing is consistent with what another user reported in a Discord thread. When switching between tabs, especially if one tab doesn't require authentication, it can trigger a logout. This is because tabs share
localStorage
, and if one tab encounters a 401 error, it clears the auth token for all tabs. Discord support thread (https://discord.com/channels/686873244791210014/1217167281612656751)
3. Wasp uses sessions stored in localStorage
on the client and in the database on the server for authentication. When a logout occurs, the session is deleted from both places. Auth Overview (https://wasp-lang.dev/docs/auth/overview#sessions)
The Wasp team is aware of this issue and is working on a solution. In the meantime, there isn't a straightforward workaround available. The team is considering differentiating between invalid/old auth and requests without an auth token to prevent this scenario from happening.
If this issue is critical for your application, you might want to consider temporarily disabling the auto-logout behavior on 401 responses, but this would require modifying the Wasp core functionality, which is not recommended.
For now, the best course of action is to wait for an official fix from the Wasp team. You can follow the progress on the GitHub issue linked above.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Sven, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?solved
was loggedout on the one tab
which caused other tab to think i was logged out too
so logging in on both tabs
worked
Glad you fixed it!
Although it would be better if you got logged in in both tabs instead of logged out.
We'll have to look into that
@Filip This is caused by the aggressive strategy we have for clearing out auth token on 401, we have that documeinted here: https://github.com/wasp-lang/wasp/issues/1227 . I will add link to this convo.
GitHub
Revisit auth token clearing behavior on 401 responses · Issue #1227...
Currently, when we get a 401 response, we clear the auth token: wasp/waspc/data/Generator/templates/react-app/src/api.ts Lines 36 to 41 in 226ec39 api.interceptors.response.use(undefined, (error) =...