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: e.getIdToken is not a function #128

Closed
louisnt-prod opened this issue Apr 8, 2021 · 6 comments · Fixed by #130
Closed

TypeError: e.getIdToken is not a function #128

louisnt-prod opened this issue Apr 8, 2021 · 6 comments · Fixed by #130
Labels
bug Something isn't working

Comments

@louisnt-prod
Copy link

louisnt-prod commented Apr 8, 2021

Describe the bug
Type error when launching next-firebase-auth linked to getIdToken function.

Version

  "firebase": "^8.3.2",
   "firebase-admin": "^9.6.0",
   "next": "^10.1.2",
   "next-firebase-auth": "^0.13.0-alpha.3",
   "react": "^17.0.2",
   "react-dom": "^17.0.2",

To Reproduce
Steps to reproduce the behavior:

  1. Wrap a static landing page with withAuthUser
    export default withAuthUser()(LandingPage);

  2. Launch
    yarn dev

  3. The error is linked to createAuthUser

Uncaught (in promise) TypeError: e.getIdToken is not a function
    at Object.eval (index.browser.js?3144:1)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (asyncToGenerator.js?c973:3)
    at _next (asyncToGenerator.js?c973:25)
    at eval (asyncToGenerator.js?c973:32)
    at new Promise (<anonymous>)
    at Object.eval (asyncToGenerator.js?c973:21)
    at Object.eval [as getIdToken] (index.browser.js?3144:1)
    at eval (index.browser.js?3144:1)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (asyncToGenerator.js?c973:3)
    at _next (asyncToGenerator.js?c973:25)
    at eval (asyncToGenerator.js?c973:32)
    at new Promise (<anonymous>)
    at eval (asyncToGenerator.js?c973:21)
    at eval (index.browser.js?3144:1)
    at eval (index.browser.js?3144:1)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (asyncToGenerator.js?c973:3)
    at _next (asyncToGenerator.js?c973:25)
    at eval (asyncToGenerator.js?c973:32)
    at new Promise (<anonymous>)
    at eval (asyncToGenerator.js?c973:21)
    at eval (index.browser.js?3144:1)
    at Object.eval (index.browser.js?3144:1)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (asyncToGenerator.js?c973:3)
    at _next (asyncToGenerator.js?c973:25)

Expected behavior
Understand where the error comes from and correct it

Additional context
Add any other context about the problem here.

Thank you for your help!

@louisnt-prod
Copy link
Author

louisnt-prod commented Apr 8, 2021

FYI, I downgraded to 0.12.2, no issue with this version in case someone is facing the same issue.

@Twister42
Copy link

Same problem here, works with alpha.0

@aprendendofelipe
Copy link

This problem starts in 0.13.0-alpha.2

@kmjennison
Copy link
Contributor

Thanks for the report. I'm able to reproduce and am working on a fix. It looks like the problem is that we used the spread operator to modify the JS SDK Firebase user (in useFirebaseUser.js), but doing that drops its methods.

@kmjennison kmjennison added the bug Something isn't working label Apr 8, 2021
@litewarp
Copy link
Contributor

litewarp commented Apr 8, 2021

@kmjennison Just about to say that!

The easiest fix is to change the function in createAuthUser to

getIdToken: async () => firebase.auth.currentUser.getIdToken()

But that blows up the test coverage, but it feels like you're better at that, so hopefully it won't take too long. The other option is to pass the user and the claims separately to the setAuthCookie function.

Also another workaround atm is to use the customTokenHandler and call firebase.auth.currentUser.getIdToken() in that function.

Edit: It looks like you can just clone the firebaseUser object and mutate the clone directly, e.g., firebaseUserWithClaims.claims = idTokenResult.claims. Submitted a PR that should fix the issue.

@kmjennison
Copy link
Contributor

Fixed in v0.13.0-alpha.4 and updated the live example app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants