convex-session-id doesn't consistently get set
I'm using Sessions following this blog post:
https://stack.convex.dev/track-sessions-without-cookies
About 20% of the time, convex-session-id never gets set in Session storage, so my session disappears when I reload the tab. When I reference ctx.sessionId in my *WithSession backend functions, I get a consistent value, even though convex-session-id isn't set in the browser.
Am I holding it wrong? Is this a bug w Convex?
Track Sessions Without Cookies
Advice and resources for session tracking per-tab or per-browser via localStorage / sessionStorage using React Context, hooks, and some utilities to m...
3 Replies
Hey @lanthe can you share the code that uses SessionProvider?
If you want to debug this you could vendor it in and add console.logs to see what’s happening.
I’d also watch out for key collision in session storage (something wiping out the session id after it is saved).
here's what i have now, simplifying away everything else:
in main.tsx:
App.tsx:
my understanding is that this should set convex-session-id in session storage right away, but it doesn't. If I reload the page, then it does. I am currently digging around your sessions.ts to figure out what it's doing but it's slow going because I'm just not that fluent in js yet
console.logging is telling me that it successfully gets set the first time the page loads, but then that gets wiped before I can interact with it in the console. The second time the page loads, a new UUID gets generated and that one gets successfully set and stored, and doesn't get wiped.
At this point my code isn't doing much, so I'm pretty stumped?
The bad behavior only happens in chrome? Safari successfully holds on to the first session id generated
welp. i restarted chrome and now it works fine
that's 2 hours of my life i'm never getting back 😛
glad to hear it's working now! 🤷