Could not load the default credentials. Firebase and Express error

梦想与她 提交于 2021-02-08 07:50:03

问题


I have a function to signup users in my express API. Please have a look at signup route:

//Route to SIGN UP
app.post('/signup', (req, res) => {
const newUser = {
email : req.body.email,
password : req.body.password,
confirmPassword: req.body.confirmPassword,
handle: req.body.handle
}

let errors = {};
if(isEmpty(newUser.email)) errors.email = 'Must not be empty';
else if (!isEmail(newUser.email)) errors.email = 'Must be a valid email address';
if(isEmpty(newUser.password)) errors.password = 'Must not be empty';
if(newUser.password !== newUser.confirmPassword) errors.confirmPassword = 'Passwords must match';
if(isEmpty(newUser.handle)) errors.handle = 'Must not be empty';
if(Object.keys(errors).length > 0) return res.status(400).json(errors);

let token, userId;
db.doc(`/users/${newUser.handle}`).get()
.then(doc => {
if(!doc.exists) {
return firebase.auth().createUserWithEmailAndPassword(newUser.email, newUser.password)
} else {
return res.status(400).json({ handle: 'this handle already exists'})
}
})
.then(data => {
userId = data.user.uid;
return data.user.getIdToken()
})
.then(idToken => {
token = idToken;
const userCredential = {
handle: newUser.handle,
email: newUser.email,
createdAt: new Date().toISOString(),
userId
}
db.doc(`/users/${newUser.handle}`).set(userCredential);
})
.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 already in use'})
} else {
return res.status(500).json(console.log(err));
}
}
)
})
//end of SIGN UP

Postman API doesn't show anything, if I send some JSON message in my last else statement, that gets shown up in the postman.

It shows me error in powershell when I run => firebase serve

i functions: Beginning execution of "api"

Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information. at GoogleAuth.getApplicationDefaultAsync (D:\Projects\socialape\functions\node_modules\google-auth-library\build\src\auth\googleauth.js:161:19) at process._tickCallback (internal/process/next_tick.js:68:7) i functions: Finished "api" in ~1s

来源:https://stackoverflow.com/questions/58169092/could-not-load-the-default-credentials-firebase-and-express-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!