Reputation: 344
I have a user which currently exists in Firebase, however I have written JS code to getUser
which does not run.
const admin = require('firebase-admin');
module.exports = function(req, res) {
const UID = String(req.body.uid);
const YOB = String(req.body.YOB);
const gender = String(req.body.gender);
const salary = String(req.body.salary);
const hoursWorked = String(req.body.hoursWorked);
admin.auth().getUser(UID)
.then(userRecord => {
admin.database().ref('users/' + UID)
.update({
YOB: YOB,
gender: gender,
salary: salary,
hoursWorked: hoursWorked
},
() => {
res.send({
success: true
});
});
})
.catch((err) => {
res.status(422).send({
error: err
});
});
}
I'm using Postman to send the request with JSON data as follows:
{
"UID": "JjeSOpY159Pv0qonNNp200qu7wY2",
"YOB": "1985",
"gender": "Female",
"salary": "20.2",
"hoursWorked": "8"
}
Firebase:
I know that I have a stable connection to firebase because I can create users using the following code:
const admin = require('firebase-admin');
module.exports = function(req, res) {
admin.auth().createUser({})
.then(user => res.send(user))
.catch(err => res.status(422).send({ error: err}));
}
Does anyone have any ideas as to why that error could occur?
Upvotes: 2
Views: 2036
Reputation: 6761
I faced this issue when running the Firebase Backend in a local emualtor. The command I was using was firebase emulators:start --project <project-id>
. This command runs the Functions locally, but also runs the Authentication locally. The local auth caused a mismatch between what I saw on the Firebase console vs what was available locally.
To fix the issue, I needed to run only Functions locally, using this command:
firebase emulators:start --project <project-id> --only functions
Upvotes: 0