Ionic phone authentication with firebase


#1

Hello dear ionic developer I have a little problem and I ask for your help. I develop an application and I add an authentication module with firebase phone number. But I would like to add a code at the level of app.compoment.ts so that the user only has to authenticate once. so each time he is redirected to the home page.

Thank you for your possible answer


#2

Try:

@Component({
  templateUrl: 'app.component.html'
})
export class AppComponent {

  @ViewChild(Nav) private nav: Nav;

  public rootPage: any = 'SignInPage'; 

  constructor(public config: Config,
              public platform: Platform,
              private authService: AuthService,
              private swService: ServiceWorkerService,
              private logger: LoggerService) {

    this.initialiseApp();
  }

  private initialiseApp() {

    this.platform.ready().then(() => {
      this.logger.info('AppComponent: platform.ready()');
      this.swService.run();
    });

    this.authService.afAuth.authState.subscribe(user => {

        if (user) {
          this.rootPage = 'TabsPage';
        } else {
          this.rootPage = 'SignInPage';
        }
      }, () => {
        this.rootPage = 'SignInPage';
      }
    );

  }
}

See:


Auto authentication firebase is not working via app.component.ts
#3

@HackingCorp, Curious how you’re implementing phone auth in an ionic app. Are you using the reCaptcha verifier?

As far as i know, that won’t work in production…
Am I mistaken?