Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Firebase PhoneVerification #462

Closed
URvesh109 opened this issue Aug 21, 2017 · 4 comments
Closed

Firebase PhoneVerification #462

URvesh109 opened this issue Aug 21, 2017 · 4 comments
Assignees
Milestone

Comments

@URvesh109
Copy link

When user type wrong verification code, and then user again click resend, type correct verification code . User is unable to login. Phone Verification work as expected at the first time, but when user logout and try to re-login then it is not possible. We need to close the application and then login again

@greg-nagy
Copy link

it works fine for me. Do you have .catch() for the firebase.registerOrLoginWithPhone() ? Also it's relatively easy to use a previous sms code.

@URvesh109
Copy link
Author

See this is my code
firebase.login({
type: firebase.LoginType.PHONE,
phoneOptions: {
phoneNumber: "+91" + this.phoneNumber,
verificationPrompt: "The received verification code" // default "Verification code"
}
}).then(success => {
alert(success);
}, error => {
alert(error);
});

What happen at first scenario
you type 6 digit verification code right or wrong it will prompt success or error respectively
it work expected at first time

Second scenario
now if I type wrong verification code it will show error and then continuing with same verification code I type right verification code it will not run success function

So the prblm is i m not able to use route.navigate([""]) because it is not returning promise

that is the problem

@greg-nagy
Copy link

My guess is that the 2nd scenario is wrong because the user is already logged in.

Do you logout the user beetween attemps ?
Do you have a proper onAuthStateChanged() handler ?

My solution to this problem was that I handled the registration in the loginsucces and everything else in the onAuthStateChange since the user will be automatically logged in if restarts the app after a succesful login.

But it's just my 2 cents. I am learning this stuff right now :)

@URvesh109
Copy link
Author

No I dont logout the user, because user is not logged in yet user has not typed correct code.
Now the user has realize that the code is wrong and then user type correct code. Now user is logged in
and it suppose to run success function so i can run this function

firebase.getCurrentUser().then(user => {
BackendService.UID = user.uid;
this.router.navigate([""]);
});

I am not using onAuthStatChanged() handler I am using application setting to maintain the user state

Why success and error function is imp for me?
because

login(user: User) {
firebase.login({
type: firebase.LoginType.PASSWORD,
email: user.email,
password: user.password
}). .then(success => {
this.loginIndicator = false;
BackendService.isLogged = true;
firebase.getCurrentUser().then(user => {
BackendService.UID = user.uid;
this.router.navigate([""]);
});
}, error => {
this.loginIndicator = false;
alert(error);
});
}

right now I am using this functionality for my app which is on play store available for Indian people only

but i expect same thing with phone verification, but i m not able to do this. I know onAuthStateChanged()

// firebase.init({
// onAuthStateChanged: (data: any) => {
// if (data.loggedIn) {
// BackendService.isLogged = true;
// }
// else {
// BackendService.isLogged = false;
// }
// }
// });

which is basically used to save the state of user logged in or logout

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants