CodetrixStudio / CapacitorGoogleAuth

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

Crash on iOS #387

Open panstromek opened 1 month ago

panstromek commented 1 month ago

Version of the plugin: RC4

code:

      GoogleAuth.initialize({
        clientId: '...',
        grantOfflineAccess: false,
      });

      // arbitrary delay to init the UI

      // onButtonClick:
      GoogleAuth.signIn()

capacitor.config.ts entry

"GoogleAuth": {
      "clientId": "...",
      "serverClientId": "...",
      "iosClientId": "...",
      "scopes": [
        "profile",
        "email"
      ]
    }

I got the exception from test flight reports.

OS Version:          iPhone OS 15.8.2 (19H384)
Release Type:        User
Baseband Version:    6.03.01
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Last Exception Backtrace:
0   CoreFoundation                  0x181317c60 __exceptionPreprocess + 216 (NSException.m:200)
1   libobjc.A.dylib                 0x198b47ee4 objc_exception_throw + 56 (objc-exception.mm:565)
2   CoreFoundation                  0x18136ae64 +[NSException raise:format:] + 108 (NSException.m:156)
3   GoogleSignIn                    0x10165a6bc -[GIDSignIn signInWithOptions:] + 280 (GIDSignIn.m:529)
4   GoogleSignIn                    0x101659a30 -[GIDSignIn signInWithConfiguration:presentingViewController:hint:additionalScopes:callback:] + 64 (GIDSignIn.m:242)
5   App                             0x100a0d7bc closure #1 in GoogleAuth.signIn(_:) + 376 (Plugin.swift:85)
6   App                             0x100a0d7bc partial apply for closure #1 in GoogleAuth.signIn(_:) + 408 (<compiler-generated>:0)
7   App                             0x1009ffc9c thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:0)
8   libdispatch.dylib               0x180fd7094 _dispatch_call_block_and_release + 24 (init.c:1517)
9   libdispatch.dylib               0x180fd8094 _dispatch_client_callout + 16 (object.m:560)
10  libdispatch.dylib               0x180f84d44 _dispatch_main_queue_drain + 928 (queue.c:7610)
11  libdispatch.dylib               0x180f84994 _dispatch_main_queue_callback_4CF$VARIANT$mp + 36 (queue.c:7770)
12  CoreFoundation                  0x1812d3014 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 (CFRunLoop.c:1795)
13  CoreFoundation                  0x1812904f8 __CFRunLoopRun + 2544 (CFRunLoop.c:3144)
14  CoreFoundation                  0x1812a3174 CFRunLoopRunSpecific + 572 (CFRunLoop.c:3268)
15  GraphicsServices                0x1a1de2988 GSEventRunModal + 160 (GSEvent.c:2200)
16  UIKitCore                       0x183aa5a88 -[UIApplication _run] + 1080 (UIApplication.m:3511)
17  UIKitCore                       0x18383ef78 UIApplicationMain + 336 (UIApplication.m:5064)
18  App                             0x1009f88c0 main + 64 (AppDelegate.swift:6)
19  dyld                            0x100fec4d0 start + 444 (dyldMain.cpp:879)

This points to this line in the code:

https://github.com/CodetrixStudio/CapacitorGoogleAuth/blob/e808d9e642c893aab11936aee05853d27e371309/ios/Plugin/Plugin.swift#L85

Seems like it could be null pointer exception? I don't know enough about Swift to tell.

chriscant commented 1 month ago

Using the repo latest code, ie later than RC4 but don't know if different, I was able to get Google sign in to work under Capacitor 6 on an iPhone on iOS 17.6. Do you need to add await in front of your calls? If you are in an app, then miss out the initialize() parameters?

In my Android and iOS app I simply have this with no await: GoogleAuth.initialize() and then when button pressed have this to sign in: const response = await GoogleAuth.signIn();

If I restart my app and the login has been saved, then initialize won't have been called, so to log out I do this with await

        try {
          await GoogleAuth.initialize()
          await GoogleAuth.signOut()
        } catch (e) {
        }
panstromek commented 1 month ago

I don't think the problem is missing await, because the crash happens no matter how long I wait between init/signIn.

Either way, something like this shouldn't cause a full app crash anyway, it should just be a rejected Promise at worst.

MalikHamza007 commented 1 month ago

I'm facing the same issue on android the catlog is giving init error

`user: User | null = null;

constructor() { } ngOnInit(): void { GoogleAuth.initialize()

} async signIn() { this.user = await GoogleAuth.signIn() as User; console.log(this.user);

} async refresh() { const authCode = await GoogleAuth.refresh(); console.log('refresh', authCode); } async signOut() { await GoogleAuth.signOut() this.user = null; } } `

panstromek commented 1 month ago

Seems like the backtrace points to this line in GoogleSignIn iOS package:

https://github.com/google/GoogleSignIn-iOS/blob/6.2.4/GoogleSignIn/Sources/GIDSignIn.m#L529

which throws with error Your app is missing support for the following URL schemes: ...". So it seems like it's something with the url schemes, not sure what yet.

The iOS package already has new major version, btw, but I'm not sure if upgrading that could help.

davidepoletti21 commented 1 month ago

same problem, i downgraded to rc.v2. For IOS works but not for Android, the opposite as v4.

Update: i deleted the plugin and reinstalled last version "@codetrix-studio/capacitor-google-auth": "github:CodetrixStudio/CapacitorGoogleAuth", now it's working also for IOS.. really weird

timstoute commented 1 month ago

@davidepoletti21 - I agree - this bug is super weird - can you confirm which version you have now that you "reinstalled last version" - do you mean you're on 3.3.6 and not one of the release candidates and it's working for you?

davidepoletti21 commented 1 month ago

@davidepoletti21 - I agree - this bug is super weird - can you confirm which version you have now that you "reinstalled last version" - do you mean you're on 3.3.6 and not one of the release candidates and it's working for you?

that's the problem. I did npm install "CodetrixStudio/CapacitorGoogleAuth and if i check the version with npm list it says 3.4.0-rc.4. But some days ago with that version IOS wasn't working, deleted and reinstalled and now it's working either on Android and IOS.. who knows

jhenriquez07 commented 4 weeks ago

@davidepoletti21 @panstromek I'm having the same issues with version3.4.0-rc.4. and capacitor 6. any solution to work properly ios/android?

davidepoletti21 commented 4 weeks ago

@jhenriquez07 no i'm still getting the problem. Even if on my device is working i'm receiving many feedback about crash on IOS with google sign-in. Apple review also rejected my last build because of that

Afolabidivia commented 4 weeks ago

@jhenriquez07 @davidepoletti21 I believe you should call the GoogleAuth.initialize method regardless of whether the platform is web or not.

jhenriquez07 commented 4 weeks ago

@jhenriquez07 @davidepoletti21 I believe you should call the GoogleAuth.initialize method regardless of whether the platform is web or not.

thanks. that's it now ios and android works fine

panstromek commented 3 weeks ago

In my case, the crash seems to go away when I remove clientId from the initialize call (based on this comment https://github.com/CodetrixStudio/CapacitorGoogleAuth/issues/378#issuecomment-2290472677):

      GoogleAuth.initialize({
//        clientId: '...',
        grantOfflineAccess: false,
      });

The problem seems to be that this clientId (in my case) was not the correct clientId for iOS. I'll see if this fixes the issue for other users and works for all platforms when I release a new version of the app.


Either way - the crash is definitely a problem. The plugin should catch the exception thrown by the Google Auth library and reject the promise with the error message instead.

riderx commented 3 weeks ago

I made a PR to update the doc for v6. ClientId is now use in priority from initialize function. If you want to keep the same behavior as before do not send it in mobile. Or send the right one for each platform