In a Firebase Cloud Function running Express, I am attempting to set custom user claims when a client posts a token to a setCustomClaims
route. When I call admin.auth().setCustomUserClaims(uid, {admin: true})
within that route, I get an error saying this is "not a function."
My authentication provider is the email/password provider via Firebase authentication (i.e. I am not creating custom tokens).
Do I have to be creating custom tokens to set custom user claims?
Here is my cloud function code:
const functions = require('firebase-functions');
const admin = require("firebase-admin");
import express from "express"
admin.initializeApp(functions.config().firebase);
const app = express()
app.post('/setCustomClaims', (req, res) => {
uid = "some-uid"
admin.auth().setCustomUserClaims(uid, {admin:true}).then(()=> {
res.end(JSON.stringify( { status: 'success' } ) );
})
});
export let api = functions.https.onRequest((request, response) => {
if (!request.path) {
request.url = `/${request.url}` // prepend '/' to keep query params if any
}
return app(request, response)
})
setCustomUserClaims
is not a function? or by any chance theres.end(
typo is also in your real code? - user2520818setCustomUserClaims
was introduced very recently in version 5.3 of the Firebase Admin SDK for Node.js. Can you check what version offirebase-admin
you are on? - Frank van Puffelen