I'm using firebase-admin on a node server
Initializing the admin app works fine:
const admin = require('firebase-admin')
const serviceAccount = require('../service-account.json')
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: // firebaseio.com url
})
admin.auth().verifyIdToken(token).then((decoded) => {
// THIS WORKS SUCCESS! a decoded token
console.log('decoded', decoded)
// now look up the user information
admin.auth().getUser(decoded.uid).then((userRecord) => {
console.log('got user record', userRecord)
}).catch((err) => {
// { [Error: An internal error has occurred.]
// errorInfo:
// { code: 'auth/internal-error',
// message: 'An internal error has occurred.' } }
console.error(err)
})
})
The last part to getUser fails with
{ [Error: An internal error has occurred.] errorInfo: { code: 'auth/internal-error', message: 'An internal error has occurred.' } }
When I tried to pass in the credential the other recommended way, I got this:
const admin = require('firebase-admin')
admin.initializeApp({
credential: admin.credential.cert({
projectId: //projectid,
clientEmail: //client email,
privateKey: //admin private key
}),
databaseURL: // firebaseio.com url
})
Then when I try to verify and look up a user:
admin.auth().verifyIdToken(token).then((decoded) => {
// THIS WORKS SUCCESS! a decoded token
console.log('decoded', decoded)
// now look up the user information
admin.auth().getUser(decoded.uid).then((userRecord) => {
console.log('got user record', userRecord)
}).catch((err) => {
// Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
console.error(err)
})
})
The last part to getUser fails with
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line