Skip to content

Commit b9fb5a3

Browse files
authored
Create firebase-setup.md
1 parent 96d676b commit b9fb5a3

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

docs/firebase-setup.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Firebase Setup
2+
3+
The Firestack library is intended on making it easy to work with [Firebase](https://firebase.google.com/) and provides a small native shim to the Firebase native code.
4+
5+
To add Firebase to your project, make sure to create a project in the [Firebase console](https://firebase.google.com/console)
6+
7+
![Create a new project](http://d.pr/i/17cJ2.png)
8+
9+
Each platform uses a different setup method after creating the project.
10+
11+
## iOS
12+
13+
After creating a Firebase project, click on the [Add Firebase to your iOS app](http://d.pr/i/3sEL.png) and follow the steps from there to add the configuration file. You do _not_ need to set up a cocoapods project (this is already done through firestack). Make sure not to forget the `Copy Files` phase in iOS.
14+
15+
[Download the Firebase config file](https://support.google.com/firebase/answer/7015592) and place it in your app directory next to your app source code:
16+
17+
![GoogleService-Info.plist](http://d.pr/i/1eGev.png)
18+
19+
Once you download the configuration file, make sure you place it in the root of your Xcode project. Every different Bundle ID (aka, even different project variants needs their own configuration file).
20+
21+
Lastly, due to some dependencies requirements, Firestack supports iOS versions 8.0 and up. Make sure to update the minimum version of your iOS app to `8.0`.
22+
23+
## Android
24+
25+
There are several ways to setup Firebase on Android. The _easiest_ way is to pass the configuration settings in JavaScript. In that way, there is no setup for the native platform.
26+
27+
### google-services.json setup
28+
If you prefer to include the default settings in the source of your app, download the `google-services.json` file provided by Firebase in the _Add Firebase to Android_ platform menu in your Firebase configuration console.
29+
30+
Next you'll have to add the google-services gradle plugin in order to parse it.
31+
32+
Add the google-services gradle plugin as a dependency in the *project* level build.gradle
33+
`android/build.gradle`
34+
```java
35+
buildscript {
36+
// ...
37+
dependencies {
38+
// ...
39+
classpath 'com.google.gms:google-services:3.0.0'
40+
}
41+
}
42+
```
43+
44+
In your app build.gradle file, add the gradle plugin at the VERY BOTTOM of the file (below all dependencies)
45+
`android/app/build.gradle`
46+
```java
47+
apply plugin: 'com.google.gms.google-services'
48+
```
49+
50+
## Usage
51+
52+
After creating a Firebase project and installing the library, we can use it in our project by importing the library in our JavaScript:
53+
54+
```javascript
55+
import Firestack from 'react-native-firestack'
56+
```
57+
58+
We need to tell the Firebase library we want to _configure_ the project. Firestack provides a way to configure both the native and the JavaScript side of the project at the same time with a single command:
59+
60+
```javascript
61+
const firestack = new Firestack();
62+
```
63+
64+
We can pass _custom_ options by passing an object with configuration options. The configuration object will be generated first by the native configuration object, if set and then will be overridden if passed in JS. That is, all of the following key/value pairs are optional if the native configuration is set.
65+
66+
| option | type | Default Value | Description |
67+
|----------------|----------|-------------------------|----------------------------------------|
68+
| debug | bool | false | When set to true, Firestack will log messages to the console and fire `debug` events we can listen to in `js` |
69+
| bundleID | string | Default from app `[NSBundle mainBundle]` | The bundle ID for the app to be bundled with |
70+
| googleAppID | string | "" | The Google App ID that is used to uniquely identify an instance of an app. |
71+
| databaseURL | string | "" | The database root (i.e. https://my-app.firebaseio.com) |
72+
| deepLinkURLScheme | string | "" | URL scheme to set up durable deep link service |
73+
| storageBucket | string | "" | The Google Cloud storage bucket name |
74+
| androidClientID | string | "" | The Android client ID used in Google AppInvite when an iOS app has it's android version |
75+
| GCMSenderID | string | "" | The Project number from the Google Developer's console used to configure Google Cloud Messaging |
76+
| trackingID | string | "" | The tracking ID for Google Analytics |
77+
| clientID | string | "" | The OAuth2 client ID for iOS application used to authenticate Google Users for signing in with Google |
78+
| APIKey | string | "" | The secret iOS API key used for authenticating requests from our app |
79+
80+
For instance:
81+
82+
```javascript
83+
const configurationOptions = {
84+
debug: true
85+
};
86+
const firestack = new Firestack(configurationOptions);
87+
firestack.on('debug', msg => console.log('Received debug message', msg))
88+
```

0 commit comments

Comments
 (0)