# Uncaught (in promise) Error: No access token found

**URL:** <https://community.auth0.com/t/uncaught-in-promise-error-no-access-token-found/12013>\
**Category:** Get Help\
**Tags:** jwt, login, auth0\
**Created:** [May 31, 2018, 3:37pm UTC](https://community.auth0.com/t/uncaught-in-promise-error-no-access-token-found/12013 "2018-05-31T15:37:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eyl91](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eyl91/32/8146_2.png) [@eyl91](https://community.auth0.com/u/eyl91)\
**Post date:** [May 31, 2018, 3:37pm UTC](https://community.auth0.com/t/uncaught-in-promise-error-no-access-token-found/12013/1 "2018-05-31T15:37:02Z")

</div>

Hi all.

This is the first time I’m using Auth0.  
I’m using React for my app, and although the Auth0 login/signup works fine. When users opt out of signing in and try to navigate the site without logging in, it breaks and gives me this error in the console: Uncaught (in promise) Error: No access token found

This is what my Auth.js looks like:

> ```
> import history from '../../utils/history';
> import auth0 from 'auth0-js';
> import { AUTH_CONFIG } from './auth0-variables';
> 
> export default class Auth {
> auth0 = new auth0.WebAuth({
> domain: AUTH_CONFIG.domain,
> clientID: AUTH_CONFIG.clientId,
> redirectUri: AUTH_CONFIG.callbackUrl,
> audience: `https://${AUTH_CONFIG.domain}/userinfo`,
> responseType: 'token id_token',
> scope: 'openid profile'
> });
> 
> userProfile;
> 
> constructor() {
> this.login = this.login.bind(this);
> this.logout = this.logout.bind(this);
> this.handleAuthentication = this.handleAuthentication.bind(this);
> this.isAuthenticated = this.isAuthenticated.bind(this);
> this.getAccessToken = this.getAccessToken.bind(this);
> this.getProfile = this.getProfile.bind(this);
> 
> }
> 
> login() {
> this.auth0.authorize();
> }
> 
> handleAuthentication() {
> this.auth0.parseHash((err, authResult) => {
> if (authResult && authResult.accessToken && authResult.idToken) {
> this.setSession(authResult);
> history.replace('/');
> } else if (err) {
> history.replace('/');
> console.log(err);
> alert(`Error: ${err.error}. Check the console for further details.`);
> }
> });
> }
> 
> setSession(authResult) {
> // Set the time that the access token will expire at
> let expiresAt = JSON.stringify((authResult.expiresIn * 1000) + new Date().getTime());
> localStorage.setItem('access_token', authResult.accessToken);
> localStorage.setItem('id_token', authResult.idToken);
> localStorage.setItem('expires_at', expiresAt);
> // navigate to the home route
> history.replace('/');
> }
> 
> getAccessToken() {
> const accessToken = localStorage.getItem('access_token');
> if (!accessToken) {
> throw new Error('No access token found');
> }
> return accessToken;
> }
> 
> getProfile(cb) {
> let accessToken = this.getAccessToken();
> this.auth0.client.userInfo(accessToken, (err, profile) => {
> if (profile) {
> this.userProfile = profile;
> }
> cb(err, profile);
> });
> }
> 
> logout() {
> // Clear access token and ID token from local storage
> localStorage.removeItem('access_token');
> localStorage.removeItem('id_token');
> localStorage.removeItem('expires_at');
> // navigate to the home route
> history.replace('/');
> }
> 
> isAuthenticated() {
> // Check whether the current time is past the 
> // access token's expiry time
> let expiresAt = JSON.parse(localStorage.getItem('expires_at'));
> return new Date().getTime() < expiresAt;
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![James.Morrison](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/james.morrison/32/13507_2.png) [@James.Morrison](https://community.auth0.com/u/James.Morrison)\
**Post date:** [December 18, 2018, 9:48pm UTC](https://community.auth0.com/t/uncaught-in-promise-error-no-access-token-found/12013/2 "2018-12-18T21:48:51Z")

</div>

Hey @eyl91,

As it has been more than a few months since this topic was opened and there has been no reply or further information provided from the community as to the existence of the issue we would like to check if you are still facing the described challenge?

We are more than happy to assist in any way! If the issue is still out there please let us know so we can create a new thread for better visibility, otherwise we’ll close this one in week’s time.

Thank you!

---

<div class="post-metadata">

**Author:** ![James.Morrison](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/james.morrison/32/13507_2.png) [@James.Morrison](https://community.auth0.com/u/James.Morrison)\
**Post date:** [December 25, 2018, 1:48pm UTC](https://community.auth0.com/t/uncaught-in-promise-error-no-access-token-found/12013/4 "2018-12-25T13:48:59Z")

</div>

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