Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when calling getAccessTokenSilently cache-only while no user is logged in #457

Closed
6 tasks done
JasonWeinzierl opened this issue Jul 24, 2023 · 3 comments · Fixed by #458
Closed
6 tasks done
Labels
bug This points to a verified bug in the code

Comments

@JasonWeinzierl
Copy link

Checklist

Description

The following causes a TypeError when no user is logged in:

    this.auth.getAccessTokenSilently({ cacheMode: 'cache-only' }).subscribe();

I would expect either a more intentional error to be thrown, or change the type annotations to indicate string | undefined and return undefined to indicate no access token is available.

Reproduction

  1. Add the above line to HomeComponent' constructor in the auth0-angular sample app
  2. Launch the app and don't log in
  3. See TypeError logged in the browser console

Additional context

home.component.ts:11 ERROR TypeError: Cannot read properties of undefined (reading 'access_token')
    at TapSubscriber._tapNext (auth0-auth0-angular.mjs:396:137)
    at TapSubscriber._next (tap.js:40:27)
    at TapSubscriber.next (Subscriber.js:49:18)
    at MergeMapSubscriber.notifyNext (mergeMap.js:70:26)
    at SimpleInnerSubscriber._next (innerSubscribe.js:10:21)
    at SimpleInnerSubscriber.next (Subscriber.js:49:18)
    at subscribeToPromise.js:5:24
    at _ZoneDelegate.invoke (zone.js:368:26)
    at Object.onInvoke (core.mjs:26249:33)
    at _ZoneDelegate.invoke (zone.js:367:52)

auth0-angular version

2.2.0

Angular version

16.1.2

Which browsers have you tested in?

Chrome, Firefox

@JasonWeinzierl JasonWeinzierl added the bug This points to a verified bug in the code label Jul 24, 2023
@JasonWeinzierl
Copy link
Author

@frederikprijck
Copy link
Member

Thanks for reporting this, I fixed it in #458

@frederikprijck
Copy link
Member

Fixed and released in v2.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This points to a verified bug in the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants