getTokenSilently throws Timeout error
See original GitHub issueDescribe the problem
I have an interval that runs every 15 minutes to update the token stored in React state. But when you leave the tab open overnight it will throw an Timeout error. There isn’t any error logged to the Auth0 logs.
What was the expected behavior?
No error thrown
Reproduction
It’s quite hard to reproduce since you need to wait for a while. Here is a simplified example of the code I’m using.
So run this and let it be in the background for a while (computer might need to be asleep) and then when you open it up there will be a runtime error thrown.
export function AuthProvider({
audience,
checkSessionInterval = CHECK_SESSION_INTERVAL,
children,
clientId,
domain,
scope = 'openid profile email',
}) {
const [state, dispatch] = useReducer(authReducer, initialState);
const auth0 = useConstant(
() =>
new Auth0Client({
audience,
domain,
scope,
client_id: clientId,
redirect_uri: window.location.origin,
})
);
const logout = useCallback(() => {
auth0.logout({ returnTo: window.location.origin });
}, [auth0]);
const checkSession = useCallback(async () => {
try {
const searchParams = new URLSearchParams(window.location.search);
if (searchParams.has('code') && searchParams.has('state')) {
const { appState } = await auth0.handleRedirectCallback();
window.history.replaceState(
{},
document.title,
window.location.pathname
);
}
const token = await auth0.getTokenSilently();
const user = await auth0.getUser();
const payload = {
token,
auth0Id: user.sub,
email: user.email,
isAuthenticated: !!user,
};
dispatch({ type: RECEIVE_SESSION, payload });
} catch (error) {
if (RECOVERABLE_ERRORS.includes(error.error)) {
auth0.loginWithRedirect();
return;
}
dispatch({ type: AUTH_ERROR, error });
}
}, [auth0]);
useEffect(() => {
checkSession();
}, [checkSession]);
useInterval(checkSession, checkSessionInterval);
const context = useMemo(() => ({ ...state, logout }), [logout, state]);
return <AuthContext.Provider value={context}>{children}</AuthContext.Provider>;
}
And here is the exact error that’s thrown

Environment
Please provide the following:
- Version of
auth0-spa-jsused: 1.12.1 - Which browsers have you tested in? Firefox
- Which framework are you using, if applicable (Angular, React, etc): React
- Other modules/plugins/libraries that might be involved: N/A
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
getTokenSilently throws Timeout error · Issue #706 - GitHub
Describe the problem We are seeing a ton of timeout errors that happen shortly after page loads and getTokenSilently is invoked.
Read more >getTokenSilently fails due to inactivity timeout
After using the UI for 30 minutes (and making those getTokenSilently calls) the getTokenSilently fails with 'login_required' errors.
Read more >@auth0/auth0-spa-js
getTokenSilently (); } catch (error) { if (error.error !== 'login_required') { throw error; } }. Logging In. You can then use login using...
Read more >How to access API with Auth0 JWT in redux? - Stack Overflow
I'm using Auth0 to secure my API endpoints with JWT. The "useAuth0().getTokenSilently()" is a context hook and it throws the "error: Invalid ......
Read more >"cloudflared access login" works but returns timeout error
Note, if I run cloudflared access tcp --hostname xxxx --url xxxx without first running the login command, it'll throw the browser window up...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks @alexandernanberg - we think that this may be resolved in #422. As that PR has not had any progress recently, we’re going to take over the work and finish it off. Will report back once it’s available.
@BjoernRave, if you haven’t managed to resolve your problem, please raise a new issue, completing the template and providing a reproducible example (if possible), so that we have all the information we need to help.