What I’m trying to do:
Understand what drives this error.
anvil.users.AuthenticationFailed: You must be logged in to call this server function
This seems to happen sporatically through out my application. This makes sense since my application wraps my server calls with the anvil.server.callable(require_user=True)
. The part I am not so sure of is what causes this to happen while my users are active and recently logged in.
Are there timeouts on user log ins that differ from session time outs?
Is the best way to address this is to add logic in my custom error handler that will request a log in when this error pops up?
Your understanding of how the Users service works is correct. My guess is that your users are for some reason not active and recently logged in - perhaps they suspended their computers and the session expired in the meantime?
Yes, that’s exactly what I’d recommend!
3 Likes
If that is the case, then you can add a timer that calls a server function every 29 minutes.
1 Like
The thing that usually gets me on similar sites (we use a bunch of Anvil apps for our internal tools, obviously!) is when I close my laptop and it goes to sleep, then wakes up an hour later and the session is gone. No timer’s going to save you from that, unfortunately - but catching the error, resetting the session and popping a login form would.
4 Likes
Thank both of you!
I think I might try a conglomeration of these ideas. That way I get activity I need when a user is just idling around between tabs and when a user walks away from their PC and NEVER CLOSES THEIR TABS. (I have some feelings about this.)