i’m trying assign custom claims using an onCall function but i get a CORS error.
This function is located in the functions folder in document adminClaim.js
and referenced in index.js
:
exports.adminClaims = require("./adminClaims");
//other functions
And the function itself
exports.addAdminRole = functions.https.onCall(async (data, context) => {
return admin
.auth()
.getUserByEmail(data.email)
.then((user) => {
return admin.auth().setCustomUserClaims(user.uid, {
admin: true,
});
})
.then(() => {
return {
message: `Success! ${data.email} has been made an admin`,
};
})
.catch((err) => {
console.log(err.message);
return err;
});
});
This is how i call the function on the client side when a user logs in:
const hostname = window.location.hostname;
const functions = getFunctions(getApp());
useEffect(() => {
if (hostname === "localhost") {
const functions = getFunctions(getApp());
connectFunctionsEmulator(functions, "127.0.0.1", 5001);
}
});
onSubmit((e) => {
const addAdminRole = httpsCallable(functions, "adminClaims/addAdminRole");
addAdminRole({ email: e.target.value }).then((result) => {
console.log("Result: ", result);
});
}
From the error, i see that the system can’t locate the function i’m calling even though its listed in the available functions or i’m not referencing it properly.
Function us-central1-addAdminRole does not exist, valid functions are:
us-central1-adminEmails-profileCreationEmail-0,
us-central1-adminClaims-addAdminRole,
us-central1-fnTracking-trackPortfolioImages,…
Any assistance would be appreciated.