isAuthenticated is false after successful login with @auth0/auth0-react

Please include the following information in your post:

  • Which SDK this is regarding: @auth0/auth0-react
  • SDK Version: 1.0.3
  • Platform Version: Node v15.11.0,
  • Code Snippets/Error Messages/Supporting Details/Screenshots:

The authentication is part of storybook add-on.

 <QueryClientProvider client={queryClient}>
  <Auth0Provider
    domain={process.env.STORYBOOK_AUTH0_ISSUER_BASE_URL}
    clientId={process.env.STORYBOOK_AUTH0_CLIENT_ID}
    redirectUri={window.location.origin}

  >

    <Auth />
    

  </Auth0Provider>
</QueryClientProvider>

Auth.js

import React, {useEffect, useRef} from ‘react’
import { useAuth0 } from ‘@auth0/auth0-react’;

const Auth = () => {
const { isAuthenticated, loginWithRedirect, logout } = useAuth0();

console.log(isAuthenticated);

return isAuthenticated ? (
<button
href="#"
color=“primary”
variant=“outlined”
onClick={() => logout({ ‘returnTo’: window.location.origin })}
>
Logout

) : (
<button
href="#"
color=“primary”
variant=“outlined”
onClick={() => loginWithRedirect()}
>
Login

);
};

There is an existing issue isAuthenticated is false after successful login · Issue #82 · auth0/auth0-react · GitHub though closed not sure if anyone else is also facing same.

Addition info on API calls which run successfully

Hi @bmhaskar,

I’m not too familiar with the storybook add-on, but it looks like the /oauth/token request is successful, so it seems like your settings are correct. I see that there is an error in the console, is that related to auth? Also, when you look at your tenant logs, do you see a failed silent auth or any other errors related to login? Thanks!

There were few silent auth failures when tried from Safari, though I have added a custom domain to avoid any of those still the issue remains.

Thanks for clarifying that you are using a Custom Domain. Usually, silent auth will fail because third-party cookies are blocked, but if a Custom Domain is used, then the browser should not block the cookies since they shouldn’t be categorized as third-party. Have you adapted your app to use the Custom Domain? For instance, the domain in the Auth0Provider component should be that of your Custom Domain. Here is documentation for configuring Auth0 features to use a Custom Domain:

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.