I'm new to using async await and I'm trying a Auth createUserWithEmailAndPassword
in firebase.
signUp
exports.signup = async (req, res) => {
const { email, password, confirmPassword, handle } = req.body
const newUser = {
email,
password,
confirmPassword,
handle
}
try {
const response = await firebase.auth().createUserWithEmailAndPassword(newUser.email, newUser.password)
const token = response.getIdToken()
console.log('THIS IS THE RESPONSE', token)
// return token
return res.status(200).json({
message: 'User Successfully Added!',
token: token
})
} catch (err) {
if (err.code === 'auth/email-already-in-use') {
return res.status(400).json({
message: 'Email already taken!'
})
} else {
return res.status(500).json({
message: 'Something went wrong, Please try again later'
})
}
}
}
My problem is this is actually creating an account but always returning a status of 500 Something went wrong, Please try again later
EDIT:
console.log(err)
gives the following output:
TypeError: response.getIdToken is not a function
I'll try to look into it.
I'm new to using async await and I'm trying a Auth createUserWithEmailAndPassword
in firebase.
signUp
exports.signup = async (req, res) => {
const { email, password, confirmPassword, handle } = req.body
const newUser = {
email,
password,
confirmPassword,
handle
}
try {
const response = await firebase.auth().createUserWithEmailAndPassword(newUser.email, newUser.password)
const token = response.getIdToken()
console.log('THIS IS THE RESPONSE', token)
// return token
return res.status(200).json({
message: 'User Successfully Added!',
token: token
})
} catch (err) {
if (err.code === 'auth/email-already-in-use') {
return res.status(400).json({
message: 'Email already taken!'
})
} else {
return res.status(500).json({
message: 'Something went wrong, Please try again later'
})
}
}
}
My problem is this is actually creating an account but always returning a status of 500 Something went wrong, Please try again later
EDIT:
console.log(err)
gives the following output:
TypeError: response.getIdToken is not a function
I'll try to look into it.
Share Improve this question edited Dec 25, 2022 at 2:04 Melchia 24.4k23 gold badges108 silver badges129 bronze badges asked Nov 11, 2019 at 0:44 code.cyclingcode.cycling 1,2742 gold badges16 silver badges33 bronze badges 3-
So what's exactly in
err
? – zerkms Commented Nov 11, 2019 at 0:46 - @zerkms I edited my question it looks like my getIdToken() is throwing an error – code.cycling Commented Nov 11, 2019 at 0:49
-
It's not
getIdToken
throws, but invokingresponse.getIdToken()
which is not a function. Where isresponse.getIdToken
defined? – zerkms Commented Nov 11, 2019 at 0:52
1 Answer
Reset to default 6createUserWithEmailAndPassword
returns Promise< UserCredential > And getIdToken
is a method of user (Documentation)
const response = await firebase.auth().createUserWithEmailAndPassword(newUser.email, newUser.password);
const token = await response.user.getIdToken(); // getIdToken is a method of user
console.log('THIS IS THE RESPONSE', token);
// return token
return res.status(200).json({
message: 'User Successfully Added!',
token: token
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744220208a4563745.html
评论列表(0条)