I get this error:

whenever this cloud function is called:
const makeAdmin = firebase.functions().httpsCallable("makeAdmin");
makeAdmin({
make: "admin"
})
.then(response => {
console.log(response);
})
.catch(err => console.error(err));
the function is:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();
const auth = admin.auth();
exports.makeAdmin = functions.https.onCall(async (data, context) => {
try {
const email = context.auth.token.email || null;
const user = await auth.getUserByEmail(email);
await auth.setCustomUserClaims(user.uid, {
admin: true
});
return {
message: "admin added successfully"
};
} catch (error) {
return error;
}
});
I tried using cors module but didn't work.
You need to enable cors, to be able to do that request:
First install the package:
npm install cors
Then import it:
const cors = require('cors')({origin: true});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With