Skip to content

Commit

Permalink
Add adminClient option for Firebase storage (#386)
Browse files Browse the repository at this point in the history
* Add adminClient option for Firebase storage

I expect this to be backward-compatible with all existing users.  The
only gotcha might be people blacklisting dynamic "require"s for webpack;
they'll need to also blacklist 'firebase-admin'.

Add documentation for the new and existing properties to the tutorial.
Also updates the example to use Firestore and adminClient.

Fixes #384

* Fix Firebase Web SDK link

* Revert package-lock.json

* add package-lock.json
  • Loading branch information
p00ya authored and nicolodavis committed Apr 13, 2019
1 parent ec7dde5 commit 8732d9f
Show file tree
Hide file tree
Showing 5 changed files with 1,185 additions and 44 deletions.
41 changes: 34 additions & 7 deletions docs/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,62 @@ server.run(8000);

### Firebase

First, install the necessary packages:
First, install the Firebase Admin Node.js SDK:

```
npm install --save firebase
npm install --save firebase-admin
```

Then modify your server spec to indicate that you want to connect to Firebase:
Download a service account key with the Cloud Datastore User role,
then modify your server spec to indicate that you want to connect to Firebase:

```js
const { Server, Firebase } = require('boardgame.io/server');
const { TicTacToe } = require('./game');
const admin = require('firebase-admin');
const serviceAccount = require('./serviceAccountKey.json');

const server = Server({
games: [TicTacToe],

db: new Firebase({
config: {
apiKey: '...',
authDomain: '...',
credential: admin.credential.cert(serviceAccount),
databaseURL: '...',
projectID: '...',
},
dbname: 'bgio',
engine: 'Firestore',
adminClient: true,
}),
});

server.run(8000);
```

#### Constructor

The `Firebase` constructor is passed an object with the following properties:

1. `config` (_object_): passed to the underlying SDK's `initializeApp` function.
See the Firebase
[Admin SDK](https://firebase.google.com/docs/admin/setup) or
[Web SDK](https://firebase.google.com/docs/web/setup) for information
on what this should contain.

2. `dbname` (_string_): the name of the database within the Firebase project.
If not provided, `bgio` is used.

3. `engine` (_string_): the underlying database engine.
Can be `Firestore` or `RTDB`. If not provided, `RTDB` is used.

4. `cacheSize` (_number_): size of the cache in games.
If not provided, 1000 is used.

5. `adminClient` (_boolean_): whether to use the Firebase Admin SDK.
If true, create a client using the Firebase Admin SDK (`firebase-admin`
module). If false or not provided, create a client using the Firebase
Web Client SDK (`firebase` module). The Admin SDK should be preferred.
Note the corresponding `config` objects are not compatible.

### Flatfile database with [node-persist](https://github.com/simonlast/node-persist)

First, install the necessary packages:
Expand Down
Loading

0 comments on commit 8732d9f

Please sign in to comment.