Skip to content

Clarifying why useAuth() returns false, then true, without refreshing? #29

@RylanSchaeffer

Description

@RylanSchaeffer

Hi! I'm using react-token-auth and I'm noticing something odd. First, here's my code for createAuthProvider

export const {useAuth, authFetch, login, logout} = createAuthProvider({
  accessTokenKey: 'access_token',
  onUpdateToken: (token) => fetch(
    `${process.env.REACT_APP_URL_BACKEND}/refresh`,
    {
      method: 'POST',
      body: token.access_token
    }).then(r => r.json())
});

And here's my simple App() component:


function App() {

  const navigate = useNavigate();
  const [isSignedIn] = useAuth();

  console.log('App isSignedIn: ', isSignedIn)
}

When I access the page, isSignedIn is logged as false and then without refreshing the page, is logged again as true:

App isSignedIn:  false [App.js:33]
App isSignedIn:  true [App.js:33]

Why is the value of isSignedIn changing without me navigating around the page? I thought this might be due to React StrictMode but I have that disabled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions