VueJS & Firebase - How to validate someone's password

Multi tool use
Multi tool use
The name of the picture


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.

8s9pKI42hN7ws sUEK,KKh7R4cIcHpx8JqB6KR XWZpI
PaSfkgbQvv6QBtPon,hmYyo2bJ qGlW2lr5buE,t,tLsMImdjOEeZlkfMX9b,j1X

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

415 Unsupported Media Type while sending json file over REST Template