Phone Authentication firebase in Ionic with cordova-plugin-firebase

Hi Sajtempler,
Thank you for devoting your time to implement phone authentication, I fllowed all the steps and the code you put, but in my android phone I have this error invalid action.
this’s my code :
1- app.module.ts :
import { BrowserModule } from ‘@angular/platform-browser’;
import { ErrorHandler, NgModule } from ‘@angular/core’;
import { IonicApp, IonicErrorHandler, IonicModule } from ‘ionic-angular’;
import { SplashScreen } from ‘@ionic-native/splash-screen’;
import { StatusBar } from ‘@ionic-native/status-bar’;

import { MyApp } from ‘./app.component’;
import { HomePage } from ‘…/pages/home/home’;

import { Firebase } from ‘@ionic-native/firebase’;

@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
Firebase,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}

2-- home.ts (login)
import { Component } from ‘@angular/core’;
import { NavController, AlertController } from ‘ionic-angular’;

import { Firebase } from ‘@ionic-native/firebase’;
import firebase from ‘firebase’;

@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage {

constructor(public navCtrl: NavController, public alertCtrl: AlertController,
public firebase: Firebase) { }

public phoneNumber: number;
public verificationId: any;
public showerror : any = ‘ok’;

public registerPhone(): void {
let phone = ‘+213’ + this.phoneNumber;

console.log('LoginPage registerPhone() phone', phone);

(<any>window).FirebasePlugin.getVerificationID(phone, id => {
  console.log("verificationID: " + id);
  this.verificationId = id;
  this.showPrompt();
}, error => {
  this.showerror = error;
  console.log("error: " + error);
});

}

public verifyCode(code): void {
console.log(code);

let credential = firebase.auth.PhoneAuthProvider.credential(this.verificationId, code);

firebase.auth().signInWithCredential(credential).then((res) => {
  console.log('SCC', res);
  this.doLogin()
})

}

public showPrompt() {
let prompt = this.alertCtrl.create({
title: ‘Verify’,
message: ‘Type code that was received via SMS’,
inputs: [
{
name: ‘code’,
placeholder: ‘Code’
},
],
buttons: [
{
text: ‘Cancel’,
handler: data => {
return;
}
},
{
text: ‘Verify’,
handler: data => {
this.verifyCode(data.code);
}
}
]
});
prompt.present();
}

public doLogin() {
console.log(‘ok’);
}

}

Thanks in advance for the help.

Hi,

make sure you have checked phone method in your firebase console, as follows:

Yes the Phone option is enable, but i get error invalid action :

.

Hi sajtempler,
This is my project, i removed plugins and dependencies, cause size of plugins and platform, please if you have time do npm install and install others needful, please can you provide your mail to send you my project to help me.

i get the same invalid action,please help me.my email:beodan95@gmail.com

I am also facing the same issue. Saying invalid action. Need a working sample code urgently :frowning:

For anyone getting “Invalid action” at (< any >window).FirebasePlugin.getVerificationID("+…, I finally made it work in my app. (@serenity, @01687072421, @aka25, etc.)

Just replaced the method:
(< any >window).FirebasePlugin.getVerificationID("+123…", id => { …

for this:
(< any >window).FirebasePlugin.verifyPhoneNumber("+123…", 60, (credential) =>{
console.log("verificationID: " + credential.verificationId);
}, function(error) {
console.error(error);
});

1 Like

My ionic app crash when the registerPhone() function runs.
What can i do for it ?

hi sajtempler,

I create all this setting that you apply, my ionic 3 app is now working but only on test mode. After releasing my ionic 3 app I get this warning.

WARNING: META-INF/gradle-plugins/com.google.gms.google-services.properties not protected by si
gnature. Unauthorized modifications to this JAR entry will not be detected. Delete or move the
 entry outside of META-INF/.

After this phone authentication doesn’t work.
What I have to do?

thanks

most likely you have to sign your app

https://developer.android.com/studio/publish/app-signing.html

Still having the issue.

hello here my phoneAthen worked the first day i built it.
but now when i log in the confirmation code is not sent to my phone and the (click)="..." do not direct me to the next page neither.
i am not getting any error … the login page just looks at me
i am running it on browser
please urgent help thanks

I created working demo for you:

1 Like

My friend, I have got “error: unknown error verifying number”. one firebase exception in the cellphone . Are you know something about that?

this is related:

1 Like

Would you be able to inform me as to wether your code is currently working? i need to use a SMS auth system aswell, and i just came across this thread!

@sajtempler
That is a great demo for firebase, thank you so much^^
Did you test on iOS ?

on android, I can use your great demo to make the firebase phone auth and push notifications.

but on iOS, I only can make the push notifications, about the phone auth, it can get the verify code,
after insert the verify code, nothing happen…

Can you help me , please?

Hey,

Unfortunately I don’t have iOS device. But it worked in one of the projects that I was involved.

here are some more info on it (go to verifyPhoneNumber section)

@sajtempler
Thanks for your help.
I will try my best, I hope I can make it