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.