You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Step 1 - Generate your `firebase-credentials.json` file
23
+
# Configure the Firebase Console
24
+
25
+
In the Firebase Console
26
+
27
+
Go to Build > Authentication > Get Started > Sign-in method > Email/Password and enable Email/Password and save it.
28
+
29
+
Also go to Build > Firestore Database > Create database. You can choose the option `Start in test mode`.
30
+
31
+
32
+
### Step 2 - Generate your `firebase-credentials.json` file
31
33
32
34
1) Go to your Firebase Project
33
35
2) Click on the engine icon (on right of "Project Overview")
@@ -40,11 +42,11 @@ example which interacts with this API example.**
40
42
⚠️ Keep `firebase-credentials.json` and `environment.ts` local,
41
43
don't commit these files, keep both on `.gitignore`
42
44
43
-
As any Firebase server, the API has adminstrative priviliges,
45
+
As any Firebase server, the API has administrative privileges,
44
46
that means the API has full permission to perform changes on the Firestore Database (and
45
-
other Firebase Resources) regardless how the Firestore Security Rules is configured.
47
+
other Firebase Resources) regardless of how the Firestore Security Rules are configured.
46
48
47
-
### Step 2 - To test your server locally:
49
+
### Step 3 - To test your server locally:
48
50
49
51
This command will start and restart your server as code changes are made,
50
52
do not use on production
@@ -54,7 +56,7 @@ do not use on production
54
56
Let's run `npm install` to install the dependencies and `npm run dev`
55
57
to start your server locally on port 3000.
56
58
57
-
#### Other commands for production environment
59
+
#### Other commands for the production environment
58
60
59
61
#### To build your server:
60
62
@@ -64,45 +66,61 @@ to start your server locally on port 3000.
64
66
65
67
npm run start
66
68
67
-
### Step 3 - Interact with your server
69
+
### Step 4 - Use Postman to test it
70
+
71
+
1. In the Firebase Console > Go to Project Overview and Click on the **Web** platform to Add a new Platform
72
+
73
+
2. Add a Nickname like "Postman" and click on Register App
74
+
75
+
3. Copy the **apiKey** field
76
+
77
+
4. Download the <aid="raw-url"downloadhref="https://raw.githubusercontent.com/RodrigoBertotti/api-example-firebase-nodejs/dev/postman_collection.json">Postman Collection</a> and import to your Postman
68
78
69
-
:iphone: Check this [Flutter project](https://github.com/RodrigoBertotti/flutter_client_for_api_example)
70
-
to interact with the server,
71
-
you can also create your own client that uses the Firebase Authentication
72
-
library, like React, Angular, Vue, etcetera.
79
+
5. Test creating an account first, after that, go to the Login request
80
+
example and pass the `apiKey` as query parameter
73
81
74
-
### Step 4 - Your time!
82
+
6. Copy the `idToken` and pass it, and pass it as header of the other requests, the header name is also `idToken`.
75
83
76
-
We are done! Customize this API on your way!
84
+
### 🚫 Permission errors
77
85
78
-
---
86
+
-#### "Only storeOwner can access"
87
+
Means you are not logged with a `buyer` claim rather
88
+
than with a user that contains the `storeOwner` claim.
89
+
90
+
-#### "You aren't the correct storeOwner"
91
+
Means you are logged with the correct claim, but you are trying to read others storeOwner's data.
92
+
93
+
-#### "Requires authentication"
79
94
80
95
## Authentication
81
96
82
97
Firebase Authentication is used to verify
83
98
if the client is authenticated on Firebase Authentication,
84
-
to do so, the client side should inform the `Authorization` header:
99
+
to do so, the client side should inform the `isToken` header:
85
100
86
-
### `Authorization` Header
101
+
### `idToken` Header
87
102
88
-
The client's token on Firebase Authentication in the format `Bearer <token>`,
89
-
it can be obtained in the client side after the authentication is performed with the
90
-
Firebase Authentication library for the client side.
103
+
The client's token on Firebase Authentication,
104
+
it can be obtained on the client side after the authentication is performed with the
105
+
Firebase Authentication library for the client side,
91
106
92
-
### Flutter Client Example on how to get the `Authorization`:
107
+
The `idToken` can be generated by the client side only.
The cache will be valid for a single request handler, so you will not have
266
-
problems of inconsistent cache on different requests, because
267
-
each request has its own cache.
268
-
269
-
But if the data changes, and you want to invalidate the cache on that
270
-
request handler, you can call `req.invalidateCache(cacheId)`, for example:
271
-
272
-
req.invalidateCache(req.params['productId']);
273
-
274
-
Calling `req.invalidateCache` will not affect the other requests.
275
-
276
-
---
255
+
[MIT](LICENSE)
277
256
278
257
## Reference
279
258
280
-
This project based part of the structure of the GitHub project [node-typescript-restify](https://github.com/vinicostaa/node-typescript-restify).
259
+
This project used as reference part of the structure of the GitHub project [node-typescript-restify](https://github.com/vinicostaa/node-typescript-restify).
281
260
Thank you [developer](https://github.com/vinicostaa/)!
0 commit comments