CodetrixStudio / CapacitorGoogleAuth

Capacitor plugin for Google Auth. Lightweight & no dependencies.
MIT License
271 stars 150 forks source link

Login on IOS with ionic and firebase fails with Plugin.swift:65: Fatal error: Unexpectedly found nil while implicitly unwrapping #292

Closed moblizeit closed 10 months ago

moblizeit commented 1 year ago

I have followed the instructions and still getting this error when i try to deploy on device.

my capacitor.config.ts has the following

plugins: { GoogleAuth: { scopes: ['profile', 'email'], serverClientId: 'xxxx.apps.googleusercontent.com', forceCodeForRefreshToken: true, }, }

i have GoogleService-info.plist added in ios/App/App

and my code to sign in looks like below

` import { Auth, GoogleAuthProvider, signInWithPopup } from '@angular/fire/auth'; import { signInWithCredential } from 'firebase/auth'; import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';

@Injectable({ providedIn: 'root' }) export class AuthenticationService {

constructor( @Optional() private auth: Auth) {

}

async googleSignIn() { let googleUser = await GoogleAuth.signIn(); const credential = GoogleAuthProvider.credential(googleUser.authentication.idToken); return signInWithCredential(this.auth, credential); } `

And this fails in xcode on clicking the sign in as below

CodetrixStudioCapacitorGoogleAuth/Plugin.swift:65: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value 2023-07-24 04:52:58.723606+0530 App[2308:582000] CodetrixStudioCapacitorGoogleAuth/Plugin.swift:65: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

if it helps below is my package.json

"dependencies": { "@angular/common": "^15.0.0", "@angular/core": "^15.0.0", "@angular/fire": "^7.5.0", "@angular/forms": "^15.0.0", "@angular/platform-browser": "^15.0.0", "@angular/platform-browser-dynamic": "^15.0.0", "@angular/router": "^15.0.0", "@capacitor/app": "5.0.2", "@capacitor/core": "5.0.3", "@capacitor/haptics": "5.0.2", "@capacitor/ios": "5.0.3", "@capacitor/keyboard": "5.0.2", "@capacitor/status-bar": "5.0.2", "@codetrix-studio/capacitor-google-auth": "^3.3.2", "@ionic/angular": "^7.0.0", "firebase": "^9.22.2", "moment": "^2.29.4", "rxjs": "~7.5.0", "tslib": "^2.3.0", "zone.js": "~0.11.4" }, "devDependencies": { "@angular-devkit/build-angular": "^15.0.0", "@angular/cli": "^15.0.0", "@angular/compiler": "^15.0.0", "@angular/compiler-cli": "^15.0.0", "@angular/language-service": "^15.0.0", "@capacitor/assets": "^2.0.4", "@capacitor/cli": "5.0.3", "@ionic/angular-toolkit": "^9.0.0", "@types/node": "^12.11.1", "ts-node": "~8.3.0", "typescript": "~4.8.4" },

nick-barth commented 1 year ago

I was receiving this error, when I did not correctly name the Plist file downloaded from google.

acidumirae commented 10 months ago

@nick-barth GoogleService-Info.plist is optional according to the README.md - I do not have it and have the same crash in this plugin.

acidumirae commented 10 months ago

In my case the error was caused by "serverClientId" at capacitor.config.json When it should be "clientId"

moblizeit commented 10 months ago

for me the GoogleService-Info.plist was not copied to the ios folder in xcode. closing it