Материал, который я использовал
- windows10
- Firebase (пожарный магазин)
- почтальон
- Javascript, express
ситуация
Я попытался зарегистрироваться на firebase и сделать данные в firestore. но происходит внутренняя ошибка. Кто-нибудь подтверждает мой код?
index. js
// Signup route
app.post('/signup', (req,res) => {
const newUser = {
email: req.body.email,
password: req.body.password,
confirmPassward: req.body.confirmPassword,
handle: req.body.handle
};
//TODO validate data
let token, userId;
db.doc(`/users/${newUser.handle}`)
.get()
.then(doc => {
if(doc.exists) {
return res.status(400).json({ hanldle: 'this hanlde is already taken'});
}else {
return firebase()
.auth()
.createUserWithEmailAndPassword(newUser.email, newUser.password);
}
})
.then((data) => {
userId = data.user.uid;
return data.usergetIdToken()
})
.then( ( idToken ) => {
token = idToken ;
const userCredentials = {
handle: newUser.handle,
email: newUser.email,
createdAt: new Date().toISOString(),
userId
};
return db.doc(`/users/${newUser.handle}`).set(userCredentials);
})
.then(() => {
return res.status(201).json({ token });
})
.catch(err => {
if(err.code === 'auth/email=already-in-use') {
return res.status(400).json({ email: 'email is alread is used '})
} else {
return res.status(500).json({ err : err.code });
}
});
});
exports.api = functions.https.onRequest(app);
Моя консоль visual studio
! functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
i functions: Beginning execution of "api"
! External network resource requested!
- URL: "http://169.254.169.254/computeMetadata/v1/instance"
- Be careful, this may be a production service.
! External network resource requested!
- URL: "http://metadata.google.internal./computeMetadata/v1/instance"
- Be careful, this may be a production service.
i functions: Finished "api" in ~9s
i functions: Beginning execution of "api"
i functions: Finished "api" in ~8s
Postman