Auth0 Javascript SPA SDK is not maintaining the isAuthenticated value true, after refreshing the page


We are using Javascript SPA SDK.

Issue: We want to use loginWithRedirect with the Javascript SPA sdk, It is working fine when we login with this option and try to redirect the URL with parameter code and state. After that we put some code if these parameters are available then we again initialize the Auth0 connection and check authentication for that user to maintain the last stage of the URL. then It shows invalid state for the user every time.
Can you please help us to resolve this issue?

Below is the code for your reference.

export async function updateAuth0OnRefresh(domain, client_id) {
await init(domain, client_id);

const isAuth0Authenticated = await isAuthenticated();

if (!isAuth0Authenticated) {        

const query =;
if (query.includes("code=") && query.includes("state=")) {

    try {
        const result = await handleRedirectCallback();

        if (result.appState && result.appState.targetUrl) {
    catch (err) {
        console.log("Error parsing redirect:", err);
    // Use replaceState to redirect the user away and remove the querystring parameters
    window.history.replaceState({}, document.title, window.location.href);


function onRedirectCallback(appState) {

    appState && appState.targetUrl
        ? appState.targetUrl
        : window.location.pathname