I'm trying to add a custom user claims on my vue project so I can change what a user can see/do. The way it works is I have an input field that I'll enter an email from a user and it will add an admin claim to it. When I went to test it, I got an object back with the error "errorInfo: Object { code: "auth/invalid-email", message: "The email address is improperly formatted." }
I already tried looking for what is wrong in my code but from the examples I found, the code seems to be right.
I'm submitting a test@test.com email which I have as an example and I checked the vue.js devtools and I'm passing a string with test@test.com
Here is my index.js functions code
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
exports.addAdminRole = functions.https.onCall(async (data, context) => {
//get user and add custom claim (admin)
try {
const user = await admin.auth().getUserByEmail(data.email);
await admin.auth().setCustomUserClaims(user.uid, {
admin: true
});
return {
message: `Success! has been made admin`
};
} catch (err) {
return err;
}
});
And here is my vue component where I'm calling the function
<template>
<div class="home">
<h3>Welcome to Site</h3>
<h3>Add user to admin</h3>
<div class="row">
<form @submit.prevent="addAdmin()" class="col s12">
<div class="row">
<div class="input-field col s12">
<input type="email" v-model="email" required />
<label>Email</label>
</div>
</div>
<button type="submit" class="btn">Submit</button>
<router-link to="/members" class="btn grey">Cancel</router-link>
</form>
</div>
</div>
</template>
<script>
import { db, fc } from "../data/firebaseInit";
export default {
name: "home",
data() {
return {
email: null
};
},
methods: {
addAdmin() {
const addAdminRole = fc.httpsCallable("addAdminRole");
addAdminRole(this.email).then(result => {
console.log(result);
});
}
}
};
</script>