3

I am trying to give custom claims to certain users for my react web app and I couldn't get past this error.

Error:

TypeError: getCurves is not a function
./node_modules/jose/lib/registry/ec_curves.js
  2 | 
  3 | const curves = new Set()
  4 | 
> 5 | if (getCurves().includes('prime256v1')) {
  6 |   curves.add('P-256')
  7 | }
  8 | 

and this is the function the function which triggers it

admin.auth().setCustomUserClaims(uid, {
  admin: true,
})

this is how my admin sdk looks like

import * as admin from 'firebase-admin';

import serviceAccount from './Servicekey.json';

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: <databaseURL>
});

export default admin;

I used to update user profile (password, email) in similar fashion from my system but cannot do that either.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Are you sure it's coming from Firebase Admin ? – Dharmaraj Jul 09 '21 at 12:45
  • i never got such error with my web app before ... it is after using firebase-admin that i am facing this error. – Naveen Sharma Jul 09 '21 at 12:48
  • Web app? Where are you using `firebase-admin`? You *must not* use it on frontend. That has admin privileges, doesn't obey security rules and has full access to your Firebase project. You should use that in secure env like server or cloud functions only. It's not supposed to be used in frontend. – Dharmaraj Jul 09 '21 at 12:49
  • yeah ... i am just testing or basically giving just a single admin token to a user. i have no intentions of publishing it to all user base. – Naveen Sharma Jul 09 '21 at 12:57
  • I'd recommend using a node project and not react to do s or you can try Firebase Functions emulator locally. – Dharmaraj Jul 09 '21 at 12:59
  • i would take that recommendation for sure, thankyou but i do not understand what is casing this bug when it was working just fine. Also i used a different project which shares the same firebase setup and it gave me the same error. – Naveen Sharma Jul 10 '21 at 05:58

3 Answers3

0

In my case I used getToken() from next-auth

Mohamad
  • 79
  • 1
  • 2
0

I know it's been a couple of months, but I just spent several days figuring this out, I ended up reverting to an older version of firebase-admin. Try reverting to version 9.0.0.

I reverted by going to the package.json file and changing the firebase-admin version to 9.0.0 then running "npm i".

Dharman
  • 30,962
  • 25
  • 85
  • 135
Spoot
  • 91
  • 1
  • 3
0

I was also getting this error from firebase-admin v11.5 which was running in a NextJS v12 getServerSideProps function. The server was not erroring, but the client was which wasn't making any sense.

It turned out that I was running the firebase-admin verifyIdToken in my _app.tsx file in this function

MyApp.getServerSideProps = async (appContext: AppContext) => { ... }

is attached to the page component, and isn't server-side only at all, instead of this

export async function getServerSideProps(appContext: AppContext) { ... }

NOTE: after posting this I discovered that getServerSideProps will not run at all in _app.tsx, but I swear it was doing it that night, and next morning, it was not.

poshest
  • 4,157
  • 2
  • 26
  • 37