Commit 8243af25 authored by Thijs Koerselman's avatar Thijs Koerselman Committed by Luis Fernando Alvarez D

Update example with firebase auth (#8127)

* Add sessions folder to prevent errors on first run

* Update readme steps to reflect current firebase ui

* Use default directory for sessions-file-store

* Remove obsolete databaseURL from config
parent cc6fe5fd
...@@ -24,11 +24,21 @@ cd with-firebase-authentication ...@@ -24,11 +24,21 @@ cd with-firebase-authentication
Set up firebase: Set up firebase:
- Create a project at the [Firebase console](https://console.firebase.google.com/). - Create a project at the [Firebase console](https://console.firebase.google.com/).
- Get your account credentials from the Firebase console at _settings>service accounts_, where you can click on _generate new private key_ and download the credentials as a json file. It will contain keys such as `project_id`, `client_email` and `client id`. Now copy them into your project in the `credentials/server.js` file. - Get your account credentials from the Firebase console at _project settings>service accounts_, where you can click on _generate new private key_ and download the credentials as a json file. It will contain keys such as `project_id`, `client_email` and `client id`. Now copy them into your project in the `credentials/server.js` file.
- Get your authentication credentials from the Firebase console under _authentication>users>web setup_. It will include keys like `apiKey`, `authDomain` and `databaseUrl` and it goes into your project in `credentials/client.js`. - Get your authentication credentials from the Firebase console under _project settings>general>your apps_ Add a new web app if you don't already have one. Under _Firebase SDK snippet_ choose _Config_ to get the configuration as JSON. It will include keys like `apiKey`, `authDomain` and `databaseUrl` and it goes into your project in `credentials/client.js`.
- Copy the `databaseUrl` key you got in the last step into `server.js` in the corresponding line. - Back at the Firebase web console, go to _Authentication>Sign-in method_ and enable _Google_.
- Back at the Firebase web console, go to _authentication>signup method_ and select _Google_. - Create a database in the "Database" tab and select Firestore. Then go to "rules" and set up your write, read rules to this:
- Create a database in the "Database" tab and select the realtime database. Then go to "rules" and set up your write, read rules. Examples can be found here: https://firebase.google.com/docs/database/security/quickstart#sample-rules
```
// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
```
Install it and run: Install it and run:
......
...@@ -12,8 +12,7 @@ const handle = app.getRequestHandler() ...@@ -12,8 +12,7 @@ const handle = app.getRequestHandler()
const firebase = admin.initializeApp( const firebase = admin.initializeApp(
{ {
credential: admin.credential.cert(require('./credentials/server')), credential: admin.credential.cert(require('./credentials/server'))
databaseURL: '' // TODO database URL goes here
}, },
'server' 'server'
) )
...@@ -26,7 +25,7 @@ app.prepare().then(() => { ...@@ -26,7 +25,7 @@ app.prepare().then(() => {
session({ session({
secret: 'geheimnis', secret: 'geheimnis',
saveUninitialized: true, saveUninitialized: true,
store: new FileStore({ path: '/tmp/sessions', secret: 'geheimnis' }), store: new FileStore({ secret: 'geheimnis' }),
resave: false, resave: false,
rolling: true, rolling: true,
httpOnly: true, httpOnly: true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment