Я пытаюсь создать бэкэнд регистрации node.js, используя систему аутентификации Firebase, поэтому я создал конечную точку поста, которая ожидает объект в теле, который имеет: имя, адрес электронной почты, пароль, поэтому сначала я прошел аутентификацию с помощью firebase используя полученную электронную почту и pw, а затем я попытался обновить displayName пользователя, используя метод updateProfile
, но он всегда говорит, что Cannot read property 'updateProfile' of null
, а firebase.auth().currentUser
всегда null
.
Так что это конечная точка внутри сервера. js файл:
const app = express();
app.use(bodyParser.json());
app.post('/register', (req, res) => {
//create a new user with the recieved email & pw
fire.auth().createUserWithEmailAndPassword(req.body.email, req.body.password)
.then(user => {
console.log(user) //to log the new created user
})
.catch(err => { //just to log any errors if they exist
console.log(err.code)
res.json(err.message)
console.log(err.message)
})
let currentUser = fire.auth().currentUser;
console.log(currentUser) // >>>>>>> null
currentUser.updateProfile({
displayName: req.body.name
}).then(function (updatedUser) {
res.json(updatedUser) //send the new updated user
}).catch(function (error) {
console.log(error.message)
});
})