Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An error in console: Failed to load resource: the server responded with a status of 401 (Unauthorized) #9976

Closed
3 tasks done
koksikus opened this issue Nov 22, 2021 · 5 comments

Comments

@koksikus
Copy link

Preflight Checklist

Describe the Bug

In each language version, regardless of the settings, also in chrome. After about an hour or more of non-use Directus, an error appears in the console. I can still make changes in Directus. After refreshing, the error disappears. I thought it was not saving the data, but I found a description of the M2M error of the relationship. I think it would be good if the user was logged out automatically. Then the user logs in and everything refreshes. One more idea - can it be introduced that there is currently service work and please log in, in x time. During this time, no one can log in.

Zrzut ekranu 2021-11-22 120902

Or
GET and 401 (Unauthorized) vendor.299bc11cjs:74

To Reproduce

In database I have many M2M relationship (maybe this is important). After about an hour or more of non-use Directus (it is still open in the browser but I use different tabs), and when I return to it it shows an error appears in the console.

Errors Shown

No response

What version of Directus are you using?

9.0.1

What version of Node.js are you using?

16.13.0

What database are you using?

Sql server 2017

What browser are you using?

Edge

What operating system are you using?

Debian 11.1

How are you deploying Directus?

locally

@licitdev
Copy link
Member

Hmm, I wonder if the access token was successfully refreshed...

@koksikus Please help to test if adding the environment variable DB_POOL_MIN=0 resolves the issue.
If it doesn't, please keep the browser developer tools open, at the network tab to see whether /auth/refresh ran successfully prior to the 401 error. Do provide the response content of the requests that errored out.

As for your feature request, it seems to be similar with #7395.
Do upvote it or provide your comments there.

@rijkvanzanten
Copy link
Member

Just to confirm, you saw that particular error, but everything kept working as expected? You mentioned you could still make changes and whatnot. The app will automatically refresh and retry the current request if the access token happened to be expired in the meantime here:

directus/app/src/api.ts

Lines 72 to 96 in ba0e969

if (
status === 401 &&
code === 'INVALID_CREDENTIALS' &&
error.request.responseURL.includes('refresh') === false &&
error.request.responseURL.includes('login') === false &&
error.request.responseURL.includes('tfa') === false
) {
let newToken: string | undefined;
try {
newToken = await refresh();
} catch {
logout({ reason: LogoutReason.SESSION_EXPIRED });
return Promise.reject();
}
if (newToken) {
return api.request({
...error.config,
headers: {
Authorization: `Bearer ${newToken}`,
},
});
}
}

so if that's the case, this is working as expected.

@koksikus
Copy link
Author

koksikus commented Nov 22, 2021

Yes, I can still add or delete data. This has no effect on the operation of the system. I opened it on another computer and the same thing appeared. There is no size of time, it happens at different times. I'm logged in as an administrator.

Zrzut ekranu 2021-11-22 190648

After F5
Zrzut ekranu 2021-11-22 191441
In processes there is 28 items (records).

@licitdev Tomorrow I will enter an environment variable and see what happend.

@rijkvanzanten
Copy link
Member

@koksikus That might be just regular expected operations then 🙂 The app will at times cancel requests to prevent racing conditions (which you see in the first screenshot), and it'll auto refresh and handle any 401 state coming from expired tokens. Unfortunately, we can't tell the browser that we expect a 4xx / cancelled state, so it'll show them in red. This doesn't necessarily mean there's a problem though 👍🏻

I'll close this for now, as it sounds like things are operating as expected.

@koksikus
Copy link
Author

So, I understand, not to worry about such warnings in the console. Besides, the system works normally. Thanks

Zrzut ekranu 2021-11-23 073423

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants