Skip to content

Latest commit

 

History

History
 
 

firebase

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

firebase

Add Firebase Authentication to your Graphcool project 🎁

Getting Started

1. Add the template to your Graphcool service

graphcool add-template graphcool/templates/auth/firebase

2. Uncomment lines in graphcool.yml and types.graphql

The add-template command is performing three major steps:

  1. Download the source files from the src directory and put them into your service's src directory (into a subdirectory called email-password).
  2. Download the contents from graphcool.yml and append them as comments to your service's graphcool.yml.
  3. Download the contents from types.graphql and append them as comments to your service's types.graphql.

In order for the changes to take effect, you need to manually uncomment all the lines that have been added by the add-template command.

3. Configure root token

The function in firebaseAuthentication.js needs access to a root token.

After you added the template to your service, you need to have (at least) one root token configured in your service.

If the list of rootTokens in your graphcool.yml is currently empty, add the following root token to it:

rootTokens
  - authentication

Note that the name of the root token is actually not relevant. You can call it something else than authentication.

4. Deploy the service

Finally, you need to apply all the changes you just made by deploying the service:

graphcool deploy

Flow

  1. The user clicks the Login with Firebase button
  2. The Firebase Auth UI is loaded and the user accepts
  3. The app receives a Firebase Id Token
  4. Your app calls the Graphcool mutation authenticateFirebaseUser(firebaseIdToken: String!)
  5. If no user exists yet that corresponds to the passed firebaseIdToken, a new FirebaseUser node will be created
  6. In any case, the authenticateFirebaseUser(firebaseIdToken: String!) mutation returns a valid token for the user
  7. Your app stores the token and uses it in its Authorization header for all further requests to Graphcool

Setup

Create a Firebase App

Paste Firebase Admin Credentials

TODO

  • add setup info in README
  • remove logs from function