android - How to make sign out from firebase -
this code using firebase sign in. after completing verification signing out. when try sign in again same number doesn't send me otp.
help me signout it. in advance. code:
@override public void onverificationcompleted(phoneauthcredential credential) { // callback invoked in 2 situations: // 1 - instant verification. in cases phone number can instantly // verified without needing send or enter verification code. // 2 - auto-retrieval. on devices google play services can automatically // detect incoming verification sms , perform verificaiton without // user action. // log.d(tag, "onverificationcompleted:" + credential); //mauth.signout(); mauth= firebaseauth.getinstance(); if(mauth!=null) mauth.signout(); toast.maketext(mainactivity.this,"verification complete",toast.length_short).show();
}
@override public void oncodesent(string verificationid, phoneauthprovider.forceresendingtoken token) { // sms verification code has been sent provided phone number, // need ask user enter code , construct credential // combining code verification id. // log.d(tag, "oncodesent:" + verificationid); toast.maketext(mainactivity.this,"code sent",toast.length_short).show(); // save verification id , resending token can use them later mverificationid = verificationid; mresendtoken = token; mobilenumber.setvisibility(view.gone); submit.setvisibility(view.gone); otpbutton.setvisibility(view.visible); otptext.setvisibility(view.visible); t1.setvisibility(view.gone); t2.setvisibility(view.visible); mauth= firebaseauth.getinstance(); } otpbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { phoneauthcredential credential = phoneauthprovider.getcredential(mverificationid,otptext.gettext().tostring()); signinwithphoneauthcredential(credential); } }); submit.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { phoneauthprovider.getinstance().verifyphonenumber( "+91"+mobilenumber.gettext().tostring(),// phone number verify 60,// timeout duration timeunit.seconds,// unit of timeout mainactivity.this,// activity (for callback binding) mcallbacks); } }); } private void signinwithphoneauthcredential(phoneauthcredential credential) { mauth.signinwithcredential(credential) .addoncompletelistener(this, new oncompletelistener<authresult>() { @override public void oncomplete(@nonnull task<authresult> task) { if (task.issuccessful()) { toast.maketext(mainactivity.this,"verification done",toast.length_short).show(); firebaseuser user = task.getresult().getuser(); } else { if (task.getexception() instanceof firebaseauthinvalidcredentialsexception) { toast.maketext(mainactivity.this,"verification failed code invalid",toast.length_short).show(); } } } }); }
Comments
Post a Comment