strapi-plugin-firebase-authentication 1.0.9 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +415 -191
  2. package/dist/_chunks/App-Bl6D4TFu.mjs +6197 -0
  3. package/dist/_chunks/App-HfsY_18f.js +6181 -0
  4. package/dist/_chunks/{api-4hcml0jk.mjs → api-B01IAVEC.mjs} +14 -3
  5. package/dist/_chunks/{api-DPtT1Bpu.js → api-BSejy8nn.js} +14 -3
  6. package/dist/_chunks/index-4hUrKd7Y.mjs +815 -0
  7. package/dist/_chunks/index-BbVqBI3M.js +859 -0
  8. package/dist/_chunks/index-BqF9RRVF.mjs +859 -0
  9. package/dist/_chunks/index-DgfRCyyQ.js +814 -0
  10. package/dist/admin/index.js +6 -1
  11. package/dist/admin/index.mjs +7 -2
  12. package/dist/admin/src/components/PasswordResetButton/PasswordResetButton.d.ts +11 -0
  13. package/dist/admin/src/components/PasswordResetButton/index.d.ts +1 -0
  14. package/dist/admin/src/components/common/Header/Header.d.ts +12 -0
  15. package/dist/admin/src/components/common/index.d.ts +3 -0
  16. package/dist/admin/src/components/forms/CreateUserForm/CreateUserForm.d.ts +2 -0
  17. package/dist/admin/src/components/forms/EditUserForm/EditUserForm.d.ts +6 -0
  18. package/dist/admin/src/components/forms/index.d.ts +4 -0
  19. package/dist/admin/src/components/forms/shared/UserFormFields/UserFormFields.d.ts +17 -0
  20. package/dist/admin/src/components/forms/shared/UserFormLayout/UserFormLayout.d.ts +7 -0
  21. package/dist/admin/src/components/index.d.ts +5 -0
  22. package/dist/admin/src/components/search/SearchURLQuery/SearchURLQuery.d.ts +6 -0
  23. package/dist/admin/src/components/search/index.d.ts +1 -0
  24. package/dist/admin/src/components/{DynamicTable → table/FirebaseTable}/FirebaseTable.d.ts +3 -2
  25. package/dist/admin/src/components/{DynamicTable → table}/FirebaseTableRows/FirebaseTableRows.d.ts +2 -2
  26. package/dist/admin/src/components/table/index.d.ts +3 -0
  27. package/dist/admin/src/components/user-management/ResetPassword/ResetPassword.d.ts +12 -0
  28. package/dist/admin/src/components/user-management/index.d.ts +2 -0
  29. package/dist/admin/src/hooks/useBulkSelection.d.ts +14 -0
  30. package/dist/admin/src/hooks/useUserForm.d.ts +18 -0
  31. package/dist/admin/src/pages/CreateView.d.ts +1 -0
  32. package/dist/admin/src/pages/EditView.d.ts +1 -0
  33. package/dist/admin/src/pages/ListView/index.d.ts +3 -5
  34. package/dist/admin/src/pages/Settings/api.d.ts +20 -1
  35. package/dist/admin/src/pages/utils/api.d.ts +4 -1
  36. package/dist/admin/src/utils/hasPasswordProvider.d.ts +15 -0
  37. package/dist/admin/src/utils/validation.d.ts +16 -0
  38. package/dist/model/Request.d.ts +2 -0
  39. package/dist/model/User.d.ts +6 -0
  40. package/dist/server/index.js +8466 -2851
  41. package/dist/server/index.mjs +8465 -2867
  42. package/dist/server/src/config/index.d.ts +36 -1
  43. package/dist/server/src/constants/index.d.ts +107 -0
  44. package/dist/server/src/content-types/index.d.ts +82 -0
  45. package/dist/server/src/controllers/firebaseController.d.ts +32 -2
  46. package/dist/server/src/controllers/index.d.ts +16 -10
  47. package/dist/server/src/controllers/settingsController.d.ts +2 -0
  48. package/dist/server/src/controllers/userController.d.ts +1 -0
  49. package/dist/server/src/index.d.ts +194 -27
  50. package/dist/server/src/migrations/migrate-firebase-user-data.d.ts +30 -0
  51. package/dist/server/src/routes/admin.d.ts +1 -1
  52. package/dist/server/src/routes/content-api.d.ts +1 -0
  53. package/dist/server/src/routes/content-internal-api.d.ts +1 -1
  54. package/dist/server/src/routes/index.d.ts +3 -2
  55. package/dist/server/src/routes/settingsRoutes.d.ts +1 -1
  56. package/dist/server/src/services/autoLinkService.d.ts +29 -0
  57. package/dist/server/src/services/emailService.d.ts +32 -0
  58. package/dist/server/src/services/firebaseService.d.ts +87 -13
  59. package/dist/server/src/services/firebaseStrapiLinkService.d.ts +34 -0
  60. package/dist/server/src/services/firebaseUserDataService.d.ts +26 -0
  61. package/dist/server/src/services/index.d.ts +91 -16
  62. package/dist/server/src/services/settingsService.d.ts +55 -0
  63. package/dist/server/src/services/templateService.d.ts +21 -0
  64. package/dist/server/src/services/userService.d.ts +2 -1
  65. package/dist/server/src/templates/defaults/index.d.ts +2 -0
  66. package/dist/server/src/templates/defaults/magic-link.d.ts +2 -0
  67. package/dist/server/src/templates/defaults/password-reset.d.ts +2 -0
  68. package/dist/server/src/templates/types.d.ts +30 -0
  69. package/dist/server/src/utils/fetch-me.d.ts +2 -10
  70. package/dist/server/src/utils/get-user-by-id.d.ts +1 -5
  71. package/dist/server/src/utils/users.d.ts +14 -0
  72. package/package.json +32 -22
  73. package/dist/_chunks/App-B2LtHk9g.js +0 -5062
  74. package/dist/_chunks/App-B3HcVa5j.mjs +0 -5081
  75. package/dist/_chunks/index-CALp4X47.mjs +0 -110
  76. package/dist/_chunks/index-CrGRt-Ya.mjs +0 -191
  77. package/dist/_chunks/index-DMBPEFUy.js +0 -109
  78. package/dist/_chunks/index-DmTKNKJB.js +0 -191
  79. package/dist/admin/src/components/SearchURLQuery/SearchURLQuery.d.ts +0 -18
  80. package/dist/admin/src/components/UserManagement/ResetPassword.d.ts +0 -8
  81. /package/dist/admin/src/components/{Initializer.d.ts → common/Initializer/Initializer.d.ts} +0 -0
  82. /package/dist/admin/src/components/{PluginIcon.d.ts → common/PluginIcon/PluginIcon.d.ts} +0 -0
  83. /package/dist/admin/src/components/{DynamicTable → table/FirebaseTable}/TableHeaders.d.ts +0 -0
  84. /package/dist/admin/src/components/{UserManagement → user-management/DeleteAccount}/DeleteAccount.d.ts +0 -0
package/README.md CHANGED
@@ -1,297 +1,521 @@
1
1
  # Strapi Plugin Firebase Authentication
2
2
 
3
- Welcome to the Strapi plugin for Firebase Authentication! This plugin seamlessly integrates Firebase Authentication with
4
- your Strapi Headless CMS, allowing you to manage and authenticate Firebase users directly from the Strapi moderation
5
- panel. This guide will take you through the installation and configuration process and provide information on how to use
6
- this plugin with iOS and Android apps. This plugin would be enabled by default for super admins only.
3
+ [![npm version](https://img.shields.io/npm/v/strapi-plugin-firebase-authentication.svg)](https://www.npmjs.com/package/strapi-plugin-firebase-authentication)
4
+ [![npm downloads](https://img.shields.io/npm/dm/strapi-plugin-firebase-authentication.svg)](https://www.npmjs.com/package/strapi-plugin-firebase-authentication)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
6
 
8
- ## How it works
7
+ A production-ready Strapi v5 plugin that seamlessly integrates Firebase Authentication with your Strapi Headless CMS. Authenticate users via Firebase (Google, Apple, Email/Password, Phone, Magic Link) and automatically sync them with Strapi's user system.
9
8
 
10
- The Firebase Auth plugin works by authenticating users using Firebase Authentication. Once a user is authenticated, the
11
- plugin creates a Strapi user account for them if it doesn't already exist. The plugin also syncs the user's Firebase
12
- data with their Strapi account.
9
+ ## Features at a Glance
10
+
11
+ - **Multiple Authentication Methods**: Google Sign-In, Apple Sign-In, Email/Password, Phone-only, Magic Link (passwordless)
12
+ - **Automatic User Sync**: Creates and updates Strapi users from Firebase authentication
13
+ - **Password Reset Flow**: Complete password reset with email verification
14
+ - **Phone-Only Support**: Configurable email handling for phone-based authentication
15
+ - **Admin Panel**: Manage Firebase users directly from Strapi admin
16
+ - **Secure Configuration**: AES-256 encrypted Firebase credentials
17
+ - **Email Service**: Three-tier fallback (Strapi Email Plugin → Firebase Extension → Console)
18
+ - **Flexible User Lookup**: Multiple strategies (Firebase UID, email, phone, Apple relay email)
13
19
 
14
20
  ## Table of Contents
15
21
 
16
- 1. [Installation](#installation)
17
- 2. [Configuration](#configuration)
18
- 3. [Usage](#usage)
19
- 4. [Client Setup](#client-setup)
20
- 5. [Question and issues](#questions-and-issues)
22
+ 1. [Quick Reference](#quick-reference)
23
+ 2. [Installation](#installation)
24
+ 3. [Configuration](#configuration)
25
+ 4. [Features & Authentication Flows](#features--authentication-flows)
26
+ 5. [API Reference](#api-reference)
27
+ 6. [Admin Panel](#admin-panel)
28
+ 7. [Client Integration](#client-integration)
29
+ 8. [Email Templates](#email-templates)
30
+ 9. [Architecture & Database](#architecture--database)
31
+ 10. [Security](#security)
32
+ 11. [Troubleshooting](#troubleshooting)
33
+ 12. [Best Practices](#best-practices)
34
+ 13. [Support](#support)
35
+
36
+ ## Quick Reference
37
+
38
+ ### Essential Endpoints
39
+
40
+ **Authentication:**
41
+
42
+ - `POST /api/firebase-authentication` - Exchange Firebase token for Strapi JWT
43
+ - `POST /api/firebase-authentication/emailLogin` - Direct email/password login
44
+ - `POST /api/firebase-authentication/forgotPassword` - Request password reset
45
+ - `POST /api/firebase-authentication/resetPassword` - Reset with JWT token
46
+ - `POST /api/firebase-authentication/requestMagicLink` - Passwordless login
47
+ - `GET /api/firebase-authentication/config` - Get public configuration
48
+
49
+ ### Minimal Configuration
50
+
51
+ ```javascript
52
+ // config/plugins.js
53
+ module.exports = () => ({
54
+ "firebase-authentication": {
55
+ enabled: true,
56
+ config: {
57
+ FIREBASE_JSON_ENCRYPTION_KEY: process.env.FIREBASE_JSON_ENCRYPTION_KEY,
58
+ },
59
+ },
60
+ });
61
+ ```
62
+
63
+ ```bash
64
+ # .env
65
+ FIREBASE_JSON_ENCRYPTION_KEY=your-secure-32-character-key-here
66
+ ```
67
+
68
+ ### Required Setup Steps
69
+
70
+ 1. **Install:** `yarn add strapi-plugin-firebase-authentication`
71
+ 2. **Configure:** Add plugin config to `config/plugins.js`
72
+ 3. **Build:** `yarn build && yarn develop`
73
+ 4. **Upload:** Settings → Firebase Authentication → Upload service account JSON
74
+ 5. **Permissions:** Settings → Users & Permissions → Public → `firebase-authentication.authenticate` ✓
75
+
76
+ ### Admin Access
77
+
78
+ - **Settings:** Settings → Firebase Authentication
79
+ - **User Management:** Plugins → Firebase Authentication
80
+
81
+ ---
21
82
 
22
83
  ## Installation
23
84
 
24
- To get started, you need to install the Firebase Auth plugin for Strapi. We recommend using yarn for this installation.
85
+ ### Prerequisites
86
+
87
+ Before installing, ensure you have:
88
+
89
+ - Strapi v5 project (this plugin is for v5 only)
90
+ - Firebase project with Authentication enabled ([Create one](https://console.firebase.google.com/))
91
+ - Node.js 18+ and npm/yarn installed
92
+
93
+ ### Step 1: Install Plugin
94
+
95
+ ```bash
96
+ yarn add strapi-plugin-firebase-authentication
97
+ # or
98
+ npm install strapi-plugin-firebase-authentication
99
+ ```
100
+
101
+ **Verify:** Check that the plugin appears in your `package.json` dependencies.
102
+
103
+ ---
104
+
105
+ ### Step 2: Create Encryption Key
25
106
 
26
- ### Via Command Line
107
+ Generate a secure 32+ character encryption key for storing Firebase credentials:
27
108
 
28
109
  ```bash
29
- yarn add @meta-cto/strapi-plugin-firebase-auth
110
+ # Generate a random key (save this!)
111
+ node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
30
112
  ```
31
113
 
32
- Once the installation is complete, you must rebuild your Strapi instance. You can do this with the following commands:
114
+ **Common Mistake:** Using a weak or short key. The key MUST be at least 32 characters.
115
+
116
+ ---
117
+
118
+ ### Step 3: Configure Plugin
119
+
120
+ Create or edit `config/plugins.js`:
121
+
122
+ ```javascript
123
+ module.exports = () => ({
124
+ "firebase-authentication": {
125
+ enabled: true,
126
+ config: {
127
+ FIREBASE_JSON_ENCRYPTION_KEY: process.env.FIREBASE_JSON_ENCRYPTION_KEY,
128
+ },
129
+ },
130
+ });
131
+ ```
132
+
133
+ Add to `.env` file:
134
+
135
+ ```bash
136
+ FIREBASE_JSON_ENCRYPTION_KEY=your-generated-key-from-step-2
137
+ ```
138
+
139
+ **Verify:** Run `echo $FIREBASE_JSON_ENCRYPTION_KEY` to confirm it's set.
140
+
141
+ ---
142
+
143
+ ### Step 4: Build and Start
33
144
 
34
145
  ```bash
35
146
  yarn build
36
147
  yarn develop
37
148
  ```
38
149
 
39
- Alternatively, you can run Strapi in development mode with the `--watch-admin` option:
150
+ **What happens:**
40
151
 
41
- ```bash
42
- yarn develop --watch-admin
152
+ - Plugin compiles (admin + server)
153
+ - Strapi restarts with plugin enabled
154
+ - "Firebase Authentication" appears in Plugins sidebar
155
+
156
+ **Verify:** Check console output for:
157
+
158
+ ```
159
+ ✔ Building admin panel (XX.Xs)
160
+ Firebase Authentication plugin initialized
43
161
  ```
44
162
 
45
- The **Firebase Auth** plugin should now be available in the **Plugins** section of your Strapi sidebar.
163
+ **If build fails:** Run `yarn build --clean` to clear cache.
46
164
 
47
- ## Configuration
165
+ ---
48
166
 
49
- In order to configure the Firebase Auth plugin, follow these steps:
167
+ ### Step 5: Download Firebase Service Account
50
168
 
51
- ### Step 1 - Enable the Plugin
169
+ 1. Go to [Firebase Console](https://console.firebase.google.com/)
170
+ 2. Select your project
171
+ 3. Navigate to: **Project Settings** (⚙️ icon) → **Service Accounts** tab
172
+ 4. Click **"Generate New Private Key"**
173
+ 5. Download and save the JSON file securely (you'll upload this next)
52
174
 
53
- In your Strapi project, edit the `config/plugins.js` or `config/<env>/plugins.js` file to enable the Firebase Auth
54
- plugin. If the file doesn't exist, create it manually. If you already have configurations for other plugins, add
55
- the `firebase-auth` section to your existing `plugins` configuration.
175
+ **Important:** This JSON contains sensitive credentials. Never commit it to Git.
56
176
 
57
- To ensure the security of sensitive information, we have implemented a robust encryption process for the Firebase config JSON file in this project. The encrypted data is then stored as a hash in the database. Follow the steps below to set up and integrate Firebase with Strapi securely.
177
+ ---
58
178
 
59
- ```js
60
- module.exports = () => ({
61
- // ...
179
+ ### Step 6: Upload to Strapi
180
+
181
+ 1. Navigate to: **Settings → Firebase Authentication** (left sidebar)
182
+ 2. Click **"Upload Configuration"** button
183
+ 3. Select the downloaded service account JSON file
184
+ 4. Wait for "Configuration uploaded successfully" message
185
+ 5. **Restart Strapi:** `yarn develop` (important!)
186
+
187
+ **Verify:** You should see in console:
188
+
189
+ ```
190
+ Firebase Admin SDK initialized successfully
191
+ ```
192
+
193
+ **If initialization fails:** Check [Troubleshooting](#troubleshooting) section.
194
+
195
+ ---
62
196
 
63
- "firebase-auth": {
197
+ ### Step 7: Configure Permissions
198
+
199
+ Navigate to: **Settings → Users & Permissions → Roles → Public**
200
+
201
+ Enable these permissions:
202
+
203
+ - `firebase-authentication` → `authenticate` ✓
204
+
205
+ **Why:** This allows unauthenticated users to exchange Firebase tokens for Strapi JWTs.
206
+
207
+ **Verify:** The permission checkbox should be checked and saved.
208
+
209
+ ---
210
+
211
+ ### Step 8: Test Your Setup
212
+
213
+ Create a simple test to verify everything works:
214
+
215
+ **Option 1: Test with Firebase Token**
216
+
217
+ 1. Get a Firebase ID token from your client app (or Firebase Console)
218
+ 2. Send POST request to: `http://localhost:1337/api/firebase-authentication`
219
+ 3. Body: `{ "idToken": "your-firebase-token-here" }`
220
+ 4. Expected: `200 OK` with `{ user, jwt }` response
221
+
222
+ **Option 2: Test with Email/Password** (if configured)
223
+
224
+ 1. Create a user in Firebase Console
225
+ 2. Send POST to: `http://localhost:1337/api/firebase-authentication/emailLogin`
226
+ 3. Body: `{ "email": "test@example.com", "password": "password123" }`
227
+ 4. Expected: `200 OK` with `{ user, jwt }` response
228
+
229
+ **If tests fail:** Check [Troubleshooting](#troubleshooting) for common issues.
230
+
231
+ ---
232
+
233
+ ### Common Setup Mistakes
234
+
235
+ ❌ **Encryption key too short** → Must be 32+ characters
236
+ ❌ **Forgot to restart after uploading config** → Always restart Strapi
237
+ ❌ **Wrong Firebase project** → Ensure service account matches your client app
238
+ ❌ **Forgot to enable permissions** → Public role needs `authenticate` permission
239
+ ❌ **Committed service account JSON to Git** → Use `.gitignore`
240
+
241
+ ---
242
+
243
+ ### Next Steps
244
+
245
+ After successful installation:
246
+
247
+ 1. **Configure additional settings** (optional):
248
+ - Password requirements: **Settings → Firebase Authentication**
249
+ - Magic link settings (passwordless auth)
250
+ - Email templates for password reset
251
+
252
+ 2. **Integrate with your client app** (see [Client Integration](#client-integration))
253
+
254
+ 3. **Set up email service** for password reset (see [Email Templates](#email-templates))
255
+
256
+ 4. **Review security best practices** (see [Best Practices](#best-practices))
257
+
258
+ ## Configuration
259
+
260
+ The plugin is configured in two places: `config/plugins.js` and the Strapi admin panel.
261
+
262
+ **Minimal Configuration** (`config/plugins.js`):
263
+
264
+ ```javascript
265
+ module.exports = () => ({
266
+ "firebase-authentication": {
64
267
  enabled: true,
65
- config: { FIREBASE_JSON_ENCRYPTION_KEY: "encryptMe" },
268
+ config: {
269
+ FIREBASE_JSON_ENCRYPTION_KEY: process.env.FIREBASE_JSON_ENCRYPTION_KEY,
270
+ },
66
271
  },
67
-
68
- // ...
69
272
  });
70
273
  ```
71
274
 
72
- Replace `"encryptMe"` with a strong and secure key. This key will be used in the encryption and decryption process.
275
+ **Admin Panel Settings** (Settings Firebase Authentication):
276
+
277
+ - Firebase Web API Key (for email/password login)
278
+ - Password requirements (regex + message)
279
+ - Password reset URL & email subject
280
+ - Magic link settings (enable, URL, subject, expiry)
281
+ - Phone-only user handling (`emailRequired: false` for phone-only apps)
73
282
 
74
- ### Step 2: Firebase Configuration Encryption and Integration with Strapi
283
+ ## API Reference
75
284
 
76
- To ensure the security of sensitive information, we have implemented a robust encryption process for the Firebase config JSON file in this project. The encrypted data is then stored as a hash in the database. Follow the steps below to set up and integrate Firebase with Strapi securely.
285
+ ### Public Endpoints
77
286
 
78
- #### Step 1: Obtain Firebase Service Account Key
287
+ | Method | Endpoint | Purpose |
288
+ | ------ | ----------------------------------------------- | -------------------------------------- |
289
+ | POST | `/api/firebase-authentication` | Exchange Firebase token for Strapi JWT |
290
+ | POST | `/api/firebase-authentication/emailLogin` | Email/password login (no SDK required) |
291
+ | POST | `/api/firebase-authentication/forgotPassword` | Request password reset email |
292
+ | POST | `/api/firebase-authentication/resetPassword` | Reset password with JWT token |
293
+ | POST | `/api/firebase-authentication/requestMagicLink` | Request passwordless login email |
294
+ | GET | `/api/firebase-authentication/config` | Get public configuration |
79
295
 
80
- Navigate to the [Firebase Console](https://console.firebase.google.com/) and access your project. In the settings, locate the service account section and download the JSON key file. This file contains sensitive information required for Firebase Authentication.
296
+ ### Admin Endpoints
81
297
 
82
- #### Step 2: Submit Service Account Key in Strapi Settings
298
+ **User Management:**
299
+ | Method | Endpoint | Purpose |
300
+ |--------|----------|---------|
301
+ | GET | `/api/firebase-authentication/content-internal-api/users` | List/search users |
302
+ | POST | `/api/firebase-authentication/content-internal-api/users` | Create user |
303
+ | GET | `/api/firebase-authentication/content-internal-api/users/:id` | Get user |
304
+ | PUT | `/api/firebase-authentication/content-internal-api/users/:id` | Update user |
305
+ | DELETE | `/api/firebase-authentication/content-internal-api/users/:id` | Delete user |
306
+ | PUT | `/api/firebase-authentication/content-internal-api/users/resetPassword/:id` | Reset password |
83
307
 
84
- Access the Strapi admin panel and navigate to the settings page. Look for the section related to Firebase integration. Here, you will find an option to submit the `.json` service account key file. Upload the file you obtained in Step 2.
308
+ **Settings Management:**
309
+ | Method | Endpoint | Purpose |
310
+ |--------|----------|---------|
311
+ | GET/POST/DELETE | `/api/firebase-authentication/settings/firebase-config` | Manage Firebase config |
312
+ | POST | `/api/firebase-authentication/settings/password-config` | Update password/magic link settings |
85
313
 
86
- This service account key is essential for proper authentication with Firebase. It contains the necessary credentials for your Firebase project.
314
+ ---
87
315
 
88
- #### Step 3: Save Changes
316
+ ## Usage
89
317
 
90
- After submitting the service account key, make sure to save the changes in the Strapi settings. This ensures that the encrypted configuration is stored securely in the database.
91
- the `.json` [service account key file](https://firebase.google.com/docs/app-distribution/authenticate-service-account).
92
- This key is essential for Firebase Authentication to work properly.
318
+ **Basic Flow:**
93
319
 
94
- ### Step 4 - Rebuild Admin Panel
320
+ 1. User authenticates with Firebase Client SDK
321
+ 2. Client gets Firebase ID token
322
+ 3. Client sends token to Strapi: `POST /api/firebase-authentication`
323
+ 4. Plugin returns Strapi JWT for API access
95
324
 
96
- After configuring the plugin, rebuild the Strapi admin panel:
325
+ **Example (JavaScript):**
97
326
 
98
- ```bash
99
- npm run build
327
+ ```javascript
328
+ // After Firebase authentication
329
+ const idToken = await firebaseUser.getIdToken();
330
+
331
+ // Exchange with Strapi
332
+ const response = await fetch("https://your-api.com/api/firebase-authentication", {
333
+ method: "POST",
334
+ headers: { "Content-Type": "application/json" },
335
+ body: JSON.stringify({ idToken }),
336
+ });
337
+
338
+ const { user, jwt } = await response.json();
339
+ localStorage.setItem("jwt", jwt); // Use this JWT for Strapi API calls
100
340
  ```
101
341
 
102
- Alternatively, you can simply delete the existing `./build` directory.
342
+ **Resources:**
103
343
 
104
- ### Step 5 - Grant Public Permissions
344
+ - [Firebase Web SDK](https://firebase.google.com/docs/auth/web/start)
345
+ - [Firebase iOS SDK](https://firebase.google.com/docs/auth/ios/start)
346
+ - [Firebase Android SDK](https://firebase.google.com/docs/auth/android/start)
105
347
 
106
- From the Strapi admin panel, navigate to "Users-permissions" and grant public role
107
- to `{Your domain or localhost}/admin/settings/users-permissions/roles/2`. Make sure to enable public access to the
108
- Firebase Authentication endpoint.
348
+ ---
109
349
 
110
- That's it! You're ready to use Firebase Authentication in your Strapi project. Enjoy! 🎉
350
+ ## Architecture
111
351
 
112
- ## Usage
352
+ The plugin validates Firebase ID tokens and syncs users between Firebase and Strapi. Users authenticate via Firebase on the client, then exchange their Firebase token for a Strapi JWT to access your API.
353
+
354
+ **Security:**
355
+
356
+ - Firebase service account JSON encrypted with AES-256
357
+ - All tokens validated server-side via Firebase Admin SDK
358
+ - Passwords managed by Firebase (not Strapi)
359
+ - User responses automatically sanitized
360
+
361
+ ## Troubleshooting
362
+
363
+ ### 🔴 "Firebase is not initialized"
364
+
365
+ **Solution:**
366
+
367
+ 1. Verify `FIREBASE_JSON_ENCRYPTION_KEY` in `config/plugins.js` (min 32 characters)
368
+ 2. Upload Firebase service account JSON: **Settings → Firebase Authentication**
369
+ 3. Restart Strapi: `yarn develop`
370
+ 4. Check startup logs for initialization errors
371
+
372
+ ---
113
373
 
114
- ### Handling User Information
374
+ ### 🔴 "Token validation failed"
115
375
 
116
- To ensure proper handling of user information, make sure to include the following fields in the user object:
376
+ **Solution:**
117
377
 
118
- - `firebaseUserID` is the field that maps firebase user object to strapi user object.
378
+ 1. Ensure token hasn't expired (1 hour TTL) - client should obtain fresh token
379
+ 2. Verify client and server use the same Firebase project
380
+ 3. Confirm service account JSON matches your Firebase project ID
381
+ 4. Check Firebase Console for service status
119
382
 
120
- These fields can be populated during the creation of the user object if `profileMetaData` is provided.
383
+ ---
121
384
 
122
- - `firstName`
123
- - `lastName`
124
- - `phoneNumber`
125
- - `email`
385
+ ### 🔴 Email Not Sending
126
386
 
127
- #### Using `firebase-auth` Endpoint
387
+ **Solution:**
128
388
 
129
- When interacting with the `firebase-auth` endpoint, use the following JSON structure in the request body:
389
+ Install and configure Strapi Email Plugin:
130
390
 
131
- ```json
132
- {
133
- "idToken": "{{idToken}}",
134
- "profileMetaData": {
135
- "firstName": "name",
136
- "lastName": "name",
137
- "email": "email@gmail.com",
138
- "phoneNumber": "+100000000"
391
+ ```bash
392
+ yarn add @strapi/provider-email-sendgrid
393
+ ```
394
+
395
+ ```javascript
396
+ // config/plugins.js
397
+ email: {
398
+ config: {
399
+ provider: 'sendgrid',
400
+ providerOptions: { apiKey: env('SENDGRID_API_KEY') },
401
+ settings: {
402
+ defaultFrom: 'noreply@yourapp.com'
403
+ }
139
404
  }
140
405
  }
141
406
  ```
142
407
 
143
- These values will be utilized only when the user does not exist and will be ignored in other cases.
408
+ Alternative: Install [Firebase Email Extension](https://extensions.dev/extensions/firebase/firestore-send-email)
144
409
 
145
- #### Hint for strapiKMM SDK Users
410
+ ---
146
411
 
147
- If you are using our `strapiKMM SDK`, which is fully compatible with the plugin, user information will be populated automatically when signing in with Google or Apple. You don't need to manually handle these fields when using the SDK.
412
+ **Need more help?** Check [Firebase Console](https://console.firebase.google.com/) logs or [GitHub Issues](https://github.com/meta-cto/strapi-plugin-firebase-auth/issues)
148
413
 
149
- These values will be applied only when the user is being created for the first time. If the user already exists, the provided data will be ignored, and the existing user information will be retained.
414
+ ## Best Practices
150
415
 
151
- ### Client Links and Token Retrieval
416
+ - Use Firebase SDK for authentication (not `emailLogin` for production)
417
+ - Store JWTs in httpOnly cookies (production) or secure storage (mobile)
418
+ - Configure Strapi Email Plugin (SendGrid, Mailgun, SES) for production
419
+ - Implement rate limiting on public endpoints
420
+ - Enforce HTTPS for password reset URLs
421
+ - Monitor Firebase quotas regularly
422
+ - Keep dependencies updated
152
423
 
153
- To enable Firebase Authentication in your iOS, Android, or web app and obtain authentication tokens, follow the provided
154
- links and their brief descriptions:
424
+ ---
155
425
 
156
- - **Android Firebase Setup:**
157
- [Link](https://firebase.google.com/docs/android/setup)
426
+ ## Support
158
427
 
159
- _Set up Firebase Authentication in your Android app by following the instructions on this page. It will guide you
160
- through integrating Firebase into your Android project._
428
+ ### Questions and Issues
161
429
 
162
- - **iOS Firebase Setup:**
163
- [Link](https://firebase.google.com/docs/ios/setup)
430
+ If you encounter problems or have questions:
164
431
 
165
- _For iOS app integration, this link will lead you to Firebase's official documentation. It outlines the steps to add
166
- Firebase Authentication to your iOS project._
432
+ 1. **Check Troubleshooting Section:** Review common errors above
433
+ 2. **Firebase Documentation:** [firebase.google.com/docs/auth](https://firebase.google.com/docs/auth)
434
+ 3. **Strapi Documentation:** [docs.strapi.io](https://docs.strapi.io)
435
+ 4. **GitHub Issues:** [github.com/meta-cto/strapi-plugin-firebase-auth/issues](https://github.com/meta-cto/strapi-plugin-firebase-auth/issues)
436
+ - Search existing issues first
437
+ - Provide detailed information when creating new issues
167
438
 
168
- - **Web Firebase Setup:**
169
- [Link](https://firebase.google.com/docs/web/setup)
439
+ ### Creating a Bug Report
170
440
 
171
- _If you're looking to incorporate Firebase Authentication into your web application, this link provides comprehensive
172
- guidance on setting up Firebase in a web project. It's an essential resource for web-based authentication using
173
- Firebase._
441
+ When reporting issues, please include:
174
442
 
175
- ## Client setup
443
+ 1. **Plugin version:** Check `package.json`
444
+ 2. **Strapi version:** Run `yarn strapi version`
445
+ 3. **Node version:** Run `node --version`
446
+ 4. **Error message:** Full error text and stack trace
447
+ 5. **Steps to reproduce:** Detailed steps to trigger the issue
448
+ 6. **Configuration:** Relevant plugin configuration (redact sensitive data)
449
+ 7. **Expected behavior:** What should happen
450
+ 8. **Actual behavior:** What actually happens
176
451
 
177
- **Android Sample:**
452
+ ### Feature Requests
178
453
 
179
- - To set up Google Sign-In on Android, follow the official Firebase
180
- documentation: [Android Firebase Authentication with Google](https://firebase.google.com/docs/auth/android/google-signin)
181
- - After signing with Google,you need to get the GoogleAuthProvider Credential and pass it to firebaseSDK to be able to get the user token
182
- - Sample Code:
454
+ To request new features:
183
455
 
184
- ```kotlin
185
- // Obtain an ID token from Google. Use it to authenticate with Firebase.
186
- val firebaseCredential = GoogleAuthProvider.getCredential(idToken, null)
187
- auth.signInWithCredential(firebaseCredential)
188
- .addOnCompleteListener(this) { task ->
189
- if (task.isSuccessful) {
190
- val token = it.result?.token
191
- // Now, you can pass the token to the Firebase plugin by exchanging the Firebase Token using the `/firebase-auth` endpoint.
192
- } else {
193
- // If the sign-in fails, display a message to the user.
194
- Log.w(TAG, "signInWithCredential:failure", task.exception)
195
- }
196
- }
197
- ```
456
+ 1. Search existing feature requests
457
+ 2. Create detailed proposal with use case
458
+ 3. Explain why feature would be beneficial
459
+ 4. Suggest implementation approach (if applicable)
198
460
 
199
- **iOS Sample:**
461
+ ### Community
200
462
 
201
- - For iOS, use the Firebase Authentication with Google Sign-In
202
- guide: [iOS Firebase Authentication with Google](https://firebase.google.com/docs/auth/ios/google-signin)
203
- - After signing with Google,you need to get the GoogleAuthProvider Credential and pass it to firebaseSDK to be able to get the user token
463
+ - **GitHub Discussions:** Ask questions and share experiences
464
+ - **Discord:** Join Strapi community Discord server
465
+ - **Stack Overflow:** Tag questions with `strapi` and `firebase`
204
466
 
205
- - Sample Code:
467
+ ---
206
468
 
207
- ```swift
208
- guard let clientID = FirebaseApp.app()?.options.clientID else { return }
469
+ ## License
209
470
 
210
- // Create Google Sign In configuration object.
211
- let config = GIDConfiguration(clientID: clientID)
212
- GIDSignIn.sharedInstance.configuration = config
471
+ This plugin is licensed under the MIT License. See `LICENSE.md` for full details.
213
472
 
214
- // Start the sign in flow!
215
- GIDSignIn.sharedInstance.signIn(withPresenting: self) { [unowned self] result, error in
216
- guard error == nil else {
217
- // ...
218
- }
473
+ ---
219
474
 
220
- guard let user = result?.user,
221
- let idToken = user.idToken?.tokenString
222
- else {
223
- // ...
224
- }
475
+ ## Changelog
225
476
 
226
- let credential = GoogleAuthProvider.credential(withIDToken: idToken,
227
- accessToken: user.accessToken.tokenString)
477
+ See `CHANGELOG.md` for version history and release notes.
228
478
 
229
- // ...
479
+ ---
230
480
 
231
- Auth.auth().signIn(with: credential) { result, error in
481
+ ## Credits
232
482
 
233
- // At this point, our user is signed in
234
- // Now you need to pass the token to firebasePlugin using exchange the firebase Token using `/firebase-auth` endpoint
235
- }
483
+ Developed and maintained by **Meta CTO** team.
236
484
 
485
+ **Contributors:**
237
486
 
238
- }
239
- ```
487
+ - Firebase Admin SDK: Google
488
+ - Strapi Framework: Strapi Solutions SAS
489
+ - AES Encryption: crypto-js library
240
490
 
241
- **Web Sample:**
491
+ ---
242
492
 
243
- - To set up Firebase Authentication with Google Sign-In on the web, follow this Firebase
244
- documentation: [Web Firebase Authentication with Google](https://firebase.google.com/docs/auth/web/google-signin)
245
- - After signing with Google,you need to get the GoogleAuthProvider Credential and pass it to firebaseSDK to be able to get the user token
246
- - Sample Code:
493
+ ## Additional Resources
247
494
 
248
- ```javascript
249
- import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth";
250
-
251
- const auth = getAuth();
252
- signInWithPopup(auth, provider)
253
- .then((result) => {
254
- // This gives you a Google Access Token. You can use it to access the Google API.
255
- const credential = GoogleAuthProvider.credentialFromResult(result);
256
- const token = credential.accessToken;
257
- // The signed-in user info.
258
- const user = result.user;
259
- // IdP data available using getAdditionalUserInfo(result)
260
- // ...
261
- })
262
- .catch((error) => {
263
- // Handle Errors here.
264
- const errorCode = error.code;
265
- const errorMessage = error.message;
266
- // The email of the user's account used.
267
- const email = error.customData.email;
268
- // The AuthCredential type that was used.
269
- const credential = GoogleAuthProvider.credentialFromError(error);
270
- // ...
271
- });
272
- ```
495
+ **Firebase Documentation:**
496
+
497
+ - [Firebase Authentication](https://firebase.google.com/docs/auth)
498
+ - [Firebase Admin SDK](https://firebase.google.com/docs/admin/setup)
499
+ - Platform Guides: [Web](https://firebase.google.com/docs/web/setup) | [iOS](https://firebase.google.com/docs/ios/setup) | [Android](https://firebase.google.com/docs/android/setup)
273
500
 
274
- These samples will guide you on how to implement Google Sign-In and obtain the authentication token, which you can then
275
- pass to the Firebase plugin for user authentication using `/firebase-auth` endpoint
501
+ **Strapi Documentation:**
276
502
 
277
- **For More Samples:**
503
+ - [Strapi v5](https://docs.strapi.io/dev-docs/intro)
504
+ - [Email Providers](https://market.strapi.io/providers) (SendGrid, Mailgun, Amazon SES)
278
505
 
279
- If you need additional samples for authentication methods like Sign-In with Apple, Email and Password, or others, please refer to the official Firebase documentation for comprehensive details:
506
+ **Firebase Extensions:**
280
507
 
281
- - [Firebase Official Documentation](https://firebase.google.com/docs/)
508
+ - [Trigger Email Extension](https://extensions.dev/extensions/firebase/firestore-send-email)
282
509
 
283
- **Short Links to Specific Authentication Methods:**
510
+ ---
284
511
 
285
- - **Sign-In with Apple:**
286
- To ensure a smooth user login experience with Apple authentication, it’s essential to include the appleEmail field in the user object within the Strapi dashboard.
512
+ **Thank you for using Strapi Plugin Firebase Authentication!** 🎉
287
513
 
288
- - Android: [Link](https://firebase.google.com/docs/auth/android/apple)
289
- - iOS: [Link](https://firebase.google.com/docs/auth/ios/apple)
290
- - Web: [Link](https://firebase.google.com/docs/auth/web/apple)
514
+ If you find this plugin helpful, please consider:
291
515
 
292
- - **Email and Password Authentication:**
293
- - Android: [Link](https://firebase.google.com/docs/auth/android/password-auth)
294
- - iOS: [Link](https://firebase.google.com/docs/auth/ios/password-auth)
295
- - Web: [Link](https://firebase.google.com/docs/auth/web/password-auth)
516
+ - Starring the GitHub repository
517
+ - Sharing with your community
518
+ - Contributing improvements
519
+ - Reporting issues to help us improve
296
520
 
297
- These short links will take you directly to Firebase's official documentation pages for each authentication method, where you can find in-depth information and code samples.
521
+ Happy coding! 🚀