VueJS & Firebase - How to validate someone's password

Multi tool use
VueJS & Firebase - How to validate someone's password
I have a web form built with VueJS that allows authenticated users to change their passwords. The backend is using Firebase, and I'm trying to validate the user's current password prior to calling the password-change API.
My code looks like this:
rules: {
...
isPreviousPassword: v => {
var credentials = await firebase.auth().currentUser
.reauthenticateWithCredential(
firebase.auth.EmailAuthProvider.credential(
firebase.auth().currentUser.email,
v)
)
return credentials || 'Your password is incorrect'
}
}
Babel refuses the code above and returns the following error:
Syntax Error: await is a reserved word
I haven't found any ways to get over this error, and none of the code snippets I found online, which are reported to work, are being blocked by Babel, which throws the same error message as above.
What's the best way to solve this?
1 Answer
1
Try to add async
to your function:
async
isPreviousPassword: async (v) => {
var credentials = await firebase.auth().currentUser
.reauthenticateWithCredential(
firebase.auth.EmailAuthProvider.credential(
firebase.auth().currentUser.email,
v)
)
return credentials || 'Your password is incorrect'
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.