Skip to content

Commit

Permalink
docs(firebase_analytics): example app initialization and docs support…
Browse files Browse the repository at this point in the history
… status (#7745)

Co-authored-by: Russell Wheatley <russellwheatley85@gmail.com>
Co-authored-by: Mike Diarmid <mike.diarmid@gmail.com>
  • Loading branch information
3 people committed Jan 5, 2022
1 parent 5034d69 commit ac21f48
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 20 deletions.
20 changes: 12 additions & 8 deletions docs/auth/social.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ Install the official [`google_sign_in`](https://pub.dev/packages/google_sign_in)

```yaml title="pubspec.yaml"
dependencies:
google_sign_in: "{{ external.google_sign_in }}"
google_sign_in: '{{ external.google_sign_in }}'
```
:::caution
Dart-only Firebase initialization isn't yet supported by `google_sign_in` plugin, if you're using Google as an auth provider you'll still have to do the [manual installation](./manual-installation.mdx) steps to integrate the Firebase configuration files.
:::

Once installed, trigger the sign-in flow and create a new credential:

```dart
Expand Down Expand Up @@ -127,7 +131,7 @@ Install the [`flutter_facebook_auth`](https://pub.dev/packages/flutter_facebook_

```yaml title="pubspec.yaml"
dependencies:
flutter_facebook_auth: "{{ external.flutter_facebook_auth }}"
flutter_facebook_auth: '{{ external.flutter_facebook_auth }}'
```

You will need to follow the steps in the plugin documentation to ensure that both the Android & iOS Facebook SDKs have been initialized
Expand Down Expand Up @@ -199,7 +203,6 @@ to `true` if your user logs in with Facebook. Should your user login using a pro
For further information, see this [issue](https://github.com/FirebaseExtended/flutterfire/issues/4612#issuecomment-782107867).
:::


## Apple

Apple [announced](https://developer.apple.com/news/?id=09122019b) that any applications using 3rd party login
Expand Down Expand Up @@ -283,12 +286,13 @@ Future<UserCredential> signInWithApple() async {
return await FirebaseAuth.instance.signInWithCredential(oauthCredential);
}
```

</TabItem>

<TabItem value="android">

At the moment, the preferable solution is blocked by this
[issue](https://github.com/FirebaseExtended/flutterfire/issues/2691).
At the moment, the preferable solution is blocked by this
[issue](https://github.com/FirebaseExtended/flutterfire/issues/2691).

</TabItem>

Expand All @@ -313,6 +317,7 @@ Future<UserCredential> signInWithApple() async {

An alternative is to use `signInWithRedirect`. In that case the browser will navigate away from your app
and you have to use `getRedirectResult` to check for authentication results during app startup.

</TabItem>
</Tabs>

Expand Down Expand Up @@ -370,7 +375,7 @@ Future<UserCredential> signInWithTwitter() async {
<TabItem value="web">

On the web, the Twitter SDK provides support for automatically handling the authentication flow using the
Twitter application details provided on the Firebase console. Ensure that the callback URL in the Firebase console is added
Twitter application details provided on the Firebase console. Ensure that the callback URL in the Firebase console is added
as a callback URL in your Twitter application on their developer console.

For example:
Expand Down Expand Up @@ -401,7 +406,6 @@ Ensure that you have setup an OAuth App from your [GitHub Developer Settings](ht
that the "GitHub" sign-in provider is enabled on the [Firebase Console](https://console.firebase.google.com/project/_/authentication/providers)
with the Client ID and Secret are set, with the callback URL set in the GitHub app.


<Tabs
defaultValue="native"
values={[
Expand Down Expand Up @@ -448,7 +452,7 @@ Future<UserCredential> signInWithGitHub() async {
<TabItem value="web">

On the web, the GitHub SDK provides support for automatically handling the authentication flow using the
GitHub application details provided on the Firebase console. Ensure that the callback URL in the Firebase console is added
GitHub application details provided on the Firebase console. Ensure that the callback URL in the Firebase console is added
as a callback URL in your GitHub application on the developer console.

For example:
Expand Down
15 changes: 15 additions & 0 deletions docs/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ Once installed, the `flutterfire` command will be globally available.

## Usage

:::note
Some plugins or platforms do not fully support Dart-only Firebase initialization **yet**, if you need to use the plugins then the [manual installation](./manual-installation.mdx) steps should be followed first.

The following table shows the current status of these plugins (plugins not shown in this table are fully supported via Dart-only Firebase initialization):
:::
| Plugin | iOS | Android | Web | macOS |
| --------- | --- | ------- | --- | ----- |
| Analytics |||||
| Crashlytics ||| N/A ||
| Dynamic Links ||| N/A | N/A |
| In-App Messaging ||| N/A ||
| Performance Monitoring |||| N/A |

In addition, [`google_sign_in` plugin](./auth/social#google) which is used by `firebase_auth` also requires manual installation.

### Generating Firebase Options

FlutterFire can now be initialized from Dart on all platforms using `Firebase.initializeApp`, however
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if (flutterVersionName == null) {

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 29
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'dart:developer';
import 'dart:io';

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';

class DefaultFirebaseConfig {
static FirebaseOptions? get platformOptions {
if (kIsWeb) {
// Web
return const FirebaseOptions(
apiKey: 'AIzaSyAgUhHU8wSJgO5MVNy95tMT07NEjzMOfz0',
authDomain: 'react-native-firebase-testing.firebaseapp.com',
databaseURL: 'https://react-native-firebase-testing.firebaseio.com',
projectId: 'react-native-firebase-testing',
storageBucket: 'react-native-firebase-testing.appspot.com',
messagingSenderId: '448618578101',
appId: '1:448618578101:web:0b650370bb29e29cac3efc',
measurementId: 'G-F79DJ0VFGS',
);
} else if (Platform.isIOS || Platform.isMacOS) {
// iOS and MacOS
return const FirebaseOptions(
appId: '1:448618578101:ios:cc6c1dc7a65cc83c',
apiKey: 'AIzaSyAHAsf51D0A407EklG1bs-5wA7EbyfNFg0',
projectId: 'react-native-firebase-testing',
messagingSenderId: '448618578101',
iosBundleId: 'com.invertase.testing',
iosClientId:
'448618578101-28tsenal97nceuij1msj7iuqinv48t02.apps.googleusercontent.com',
androidClientId:
'448618578101-a9p7bj5jlakabp22fo3cbkj7nsmag24e.apps.googleusercontent.com',
databaseURL: 'https://react-native-firebase-testing.firebaseio.com',
storageBucket: 'react-native-firebase-testing.appspot.com',
);
} else {
// Android
log("Analytics Dart-only initializer doesn't work on Android, please make sure to add the config file.");

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,12 @@ import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';

import 'firebase_config.dart';
import 'tabs_page.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: const FirebaseOptions(
apiKey: 'AIzaSyAgUhHU8wSJgO5MVNy95tMT07NEjzMOfz0',
authDomain: 'react-native-firebase-testing.firebaseapp.com',
databaseURL: 'https://react-native-firebase-testing.firebaseio.com',
projectId: 'react-native-firebase-testing',
storageBucket: 'react-native-firebase-testing.appspot.com',
messagingSenderId: '448618578101',
appId: '1:448618578101:web:772d484dc9eb15e9ac3efc',
measurementId: 'G-0N1G9FLDZE',
),
);
await Firebase.initializeApp(options: DefaultFirebaseConfig.platformOptions);
runApp(const MyApp());
}

Expand Down

0 comments on commit ac21f48

Please sign in to comment.