Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : Cannot read property 'getAuthInstance' of undefined while using login in with google IONIC

I am seeing this error while integrating signin with google in ionic using angular by referring the link given below.

Referred link: https://devdactic.com/capacitor-google-sign-in/

ERROR: enter image description here

I have tried debugging the issue and trying to search it in google but didn't find any relevant docs.

Code :

import { Component } from '@angular/core';
import '@codetrix-studio/capacitor-google-auth';
import { Plugins } from '@capacitor/core';
@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent {
  userInfo = null;
 
  constructor() { }
 
  async googleSignup() {
    const googleUser = await Plugins.GoogleAuth.signIn(null) as any;
    console.log('my user: ', googleUser);
    this.userInfo = googleUser;
  }
}

And I would like to know is there any alternative for Plugins which is deprecated in @capactior/core

like image 613
Jakka rohith Avatar asked Feb 25 '26 20:02

Jakka rohith


1 Answers

I've been struggling with this for a while, the proposed solutions didn't work for me but the following code did:

home.page.ts

import { Component } from '@angular/core';
import {GoogleAuth} from '@codetrix-studio/capacitor-google-auth';
import {Platform} from '@ionic/angular';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: [ 'home.page.scss' ],
})
export class HomePage {
  userInfo = null;

  constructor(public platform: Platform) {
    this.platform.ready().then(async () => {
      GoogleAuth.init();
    });
  }

  async googleSignup() {
    const googleUser = await GoogleAuth.signIn() as any;
    console.log('my user: ', googleUser);
    this.userInfo = googleUser;
  }
}

Then call the googleSignup from the home.page.html :

<ion-button (click)="googleSignup()">Sign in</ion-button>

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!