User gets auto logged out

Hello,
Short information about the project:
React framework, with code in Typescript. Hosted locally.
Version: @auth0/auth0-react@2.0.1
Tried on: Firefox, Chrome, Edge + Incognito mode

I seem to have a problem that my user gets auto logged out after signing in.
The redirection works great and the user gets to the right page ect after logging in.

I tried showing the users information but get “user undefined” so i double check and notices that the user gets logged out directly after logging in and being redirected to the start page. I dont understand why.

I also want to add that i double checked that the users do get logged in, when I check “User Management” → “User” I can see that the account im using to test the website have logged in, so that part is working. It just some how logs my users out directly after.

I do not use any clearState functions.

In my understanding Auth0 does not require that I use Redux or Context to save the state between different pages (maybe I understood wrong and this is the reason). But that I instead should be able to access the users login information/“isAuthenticated” from my root file (but also from components ect). This is what i came to understand from the official tutorials but also from other tutorials online.

So, what can be the reason my users get auto logged out after logging in?
I understand it is a very wide problem, but maybe someone have encountered something similar and solved it.

edit: I noticed that I get the following message in the console after the login redirection has been done:
Status: 401 Unauthorized
Referre policy: Strict-origin-cross-when-cross-origin
After some more searching i see that i have a error on the JSON object in the webdeveloper tool saying “error: access_denied”. But I also want to push on the fact that I still can see under the “User” section that I (or other users) have logged in. So I assume the access_denied happens ms after the login have been done.

Best regards,
Emy

1 Like

I make a new reply with the additional information ive found so far.
While watching the logs, the users gets “Successful login” and “Successful Exchange”.
So the user should be logged in.
I dont get the 401 error anymore since i changed how the tokend endpoint works.

What im trying to do is get the users information, and here is where i notice that the user is not logged in anymore directly after getting authenticated.

This is the code:
const Profile = () => {
const { user, isAuthenticated, isLoading } = useAuth0();

if (isLoading) {
return div>Loading …/div>;
}

if (!isAuthenticated || !user) {
return div>User is not logged in./div>;
}

return (
div>
img src={user.picture} alt={user.name} />
<h2{user.name}</h2
/div>
);
};

Firstly the “Loading…” is shown, then I always end up on the “User is not logged in” part.

Could this be some kind of async problem?
I am using typescript as mentioned earlier and when i dont use the “!user” check, the code complains that “user might be undefined”.

I am completely lost on why my users get automatically logged out after signing in successfully.

Again, as I understood, Auth0 dont need to comunnicate with any backend ect, atleast not for the isAuthenticated to do its job. It should be possible for the user to sign in and then isAuthenticated should work.
So i have not used the “oidc” for requests or the “secret” anywhere.

Im sorry that the code looks very bad, im not sure how to format it on the post and had to take away the start “<” of all blocks for it to not become weird.