directus
directus copied to clipboard
App doesn't properly refresh the session once the tab gets focus again
Describe the Bug
With an expired Token, this error message appears and first of all, it should not be an unexpected Error because we know what it is, but this time it is about the Reset Page Preferences button, by clicking on it, it will change the appearance of the data. I think there should be a refresh button.
To Reproduce
Wait until the timer expires, go to the Directus tab and see the message. Click on it and the page preferences will be changed. But it's just the token getting expired. If someone clicks on it (thinking it will solve problem) they will have even more trouble with resetting the data.
Hosting Strategy
Self-Hosted (Docker Image)
Wait until the timer expires, go to the Directus tab
So you're saying you have Directus in a background tab, and then switch back to the tab after the expiration time of the access token? What browser/version are you using? Sounds to me like the actual underlying bug here is that the app doesn't properly refresh the session once the tab gets focus again 🤔
I just did a test. I opened Directus in the refreshed tab. I opened another one tab and worked on it after about 20 minutes or a little more I switched back to the Directus tab and a list of errors appeared in the console:
GET (...) 401 (Unauthorized)
Uncaught (in promise) X {message: 'Request failed with status code 401', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …}
GET (...) 401 (Unauthorized)
Uncaught (in promise) X {message: 'Request failed with status code 401', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …}
GET (...) 401 (Unauthorized)
Uncaught (in promise) X {message: 'Request failed with status code 401', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …}
I'm using the latest version of Directus in the Edge browser.
/linear
🤖 Linear issue created! Maintainers can access it here: ENG-871
The same errors keep popping up in the background. The longer it takes, the more the console fills up with errors.
I noticed one more thing - if everything is on one computer and database and directus and I log in to the project using this computer, no error appears.
I'm using the latest version of Directus in the Edge browser.
This might be Edge's Sleeping Tabs feature: https://www.microsoft.com/en-us/edge/features/sleeping-tabs-at-work
@koksikus Can you share what is the amount of time configured for your Edge browser within Settings
-> System and performance
-> Optimize performance
-> Put inactive tabs to sleep after the specified amount of time
? Here's an example screenshot to find it in your browser:
I noticed one more thing - if everything is on one computer and database and directus and I log in to the project using this computer, no error appears.
By "everything is on one computer" and "this computer", are you accessing Directus via localhost
instead of an actual domain?
It seems like localhost
for example cannot enter such "sleep" state as Edge prevents it:
so I'm wondering if it's the reason why it worked for you when you said "one computer".
Additionally, did you configure ACCESS_TOKEN_TTL
and REFRESH_TOKEN_TTL
environment variables for your Directus setup?
Hi azrikahar, I checked, I changed the settings to 12 hours or clicked the option to completely disable this function and it didn't change anything, this message still appears. When writing about one computer, as you write, the database and directus are on one computer and I log in via localhost. I changed ACCESS_TOKEN_TTL to 120 min and REFRESH_TOKEN_TTL to 1 day. Previously, I had higher values and it didn't change anything in terms of the message that appeared, only that I force them to log in again and this way they won't click on this message, which will cause the view to fall apart. Should I do any other tests?
This only happens on the databases tab. If I'm on Directus settings tab, nothing like this happens.
@koksikus thanks for doing the additional checks on your end!
Should I do any other tests?
Would it be possible for you to help test out #20383 in your setup? That would extremely helpful to confirm whether it resolves your exact situation, just in case the way the error happens to you is still different than what I assumed.
EDIT: or perhaps you can help test it out once this merged PR gets out in the next release 👍