Add Firebase Authentication to your Graphcool project 🎁
graphcool add-template graphcool/templates/auth/firebase
The add-template
command is performing three major steps:
- Download the source files from the
src
directory and put them into your service'ssrc
directory (into a subdirectory calledemail-password
). - Download the contents from
graphcool.yml
and append them as comments to your service'sgraphcool.yml
. - Download the contents from
types.graphql
and append them as comments to your service'stypes.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.
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
.
Finally, you need to apply all the changes you just made by deploying the service:
graphcool deploy
- The user clicks the
Login with Firebase
button - The Firebase Auth UI is loaded and the user accepts
- The app receives a Firebase Id Token
- Your app calls the Graphcool mutation
authenticateFirebaseUser(firebaseIdToken: String!)
- If no user exists yet that corresponds to the passed
firebaseIdToken
, a newFirebaseUser
node will be created - In any case, the
authenticateFirebaseUser(firebaseIdToken: String!)
mutation returns a valid token for the user - Your app stores the token and uses it in its
Authorization
header for all further requests to Graphcool
- add setup info in README
- remove logs from function