Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit d93210a

Browse files
Merge pull request #734 from NathanWalker/ios-10-google-login-compat
fix(iOS): google auth issue for iOS 10 and below
2 parents 5973326 + 234aceb commit d93210a

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

docs/AUTHENTICATION.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,32 @@ Make sure the URL Scheme for `REVERSED_CLIENT_ID` is in `app/App_Resources/iOS/I
536536
</array>
537537
```
538538

539+
*NOTE:* iOS 10 and below issue for Google Auth when opening from a modal.
540+
541+
If you are planning to open Google Auth from a modal view you may encounter this error resulting in nothing happening (no google auth dialog) on iOS 10 and below:
542+
543+
```
544+
Warning: Attempt to present <SFSafariViewController: 0x7fa575968470> on <UILayoutViewController: 0x7fa575e3d710> whose view is not in the window hierarchy!
545+
```
546+
547+
To solve, you will want to pass in the appropriate iOS controller of the active view. This can be accomplished as follows:
548+
549+
```js
550+
firebase.login({
551+
type: firebase.LoginType.GOOGLE,
552+
ios: {
553+
controller: topmost().ios.controller
554+
}
555+
}).then(
556+
function (result) {
557+
JSON.stringify(result);
558+
},
559+
function (errorMessage) {
560+
console.log(errorMessage);
561+
}
562+
);
563+
```
564+
539565
#### Android
540566

541567
1. If you didn't choose this feature during installation you can uncomment `google-services-auth` in `node_modules\nativescript-plugin-firebase\platforms\android\include.gradle`

src/firebase.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ export interface FirebaseCustomLoginOptions {
236236
tokenProviderFn?: () => Promise<String>;
237237
}
238238

239+
export interface LoginIOSOptions {
240+
controller?: any;
241+
}
242+
239243
/**
240244
* The options object passed into the login function.
241245
*/
@@ -247,6 +251,7 @@ export interface LoginOptions {
247251
googleOptions?: FirebaseGoogleLoginOptions;
248252
facebookOptions?: FirebaseFacebookLoginOptions;
249253
customOptions?: FirebaseCustomLoginOptions;
254+
ios?: LoginIOSOptions;
250255

251256
/**
252257
* @deprecated Please use the 'passwordOptions?: FirebasePasswordLoginOptions' object instead.

src/firebase.ios.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,8 @@ firebase.login = arg => {
13671367
}
13681368

13691369
const sIn = GIDSignIn.sharedInstance();
1370-
sIn.uiDelegate = application.ios.rootController;
1370+
// allow custom controller for variety of use cases
1371+
sIn.uiDelegate = arg.ios && arg.ios.controller ? arg.ios.controller : application.ios.rootController;
13711372
sIn.clientID = FIRApp.defaultApp().options.clientID;
13721373

13731374
if (arg.googleOptions && arg.googleOptions.hostedDomain) {

0 commit comments

Comments
 (0)