strapi-plugin-firebase-authentication 1.0.13 → 1.1.7

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 +449 -191
  2. package/dist/_chunks/App-C49N6om4.mjs +6271 -0
  3. package/dist/_chunks/App-CtjmoTFU.js +6293 -0
  4. package/dist/_chunks/{api-DPtT1Bpu.js → api-Bw_7tM52.js} +14 -3
  5. package/dist/_chunks/{api-4hcml0jk.mjs → api-DrAXGM3H.mjs} +14 -3
  6. package/dist/_chunks/index-BkQ4pF_p.js +859 -0
  7. package/dist/_chunks/index-C9AUBuP7.mjs +859 -0
  8. package/dist/_chunks/index-FAW4iPgh.mjs +815 -0
  9. package/dist/_chunks/index-yE1zATuU.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 +6 -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 +6542 -901
  41. package/dist/server/index.mjs +6537 -913
  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 +34 -2
  46. package/dist/server/src/controllers/index.d.ts +15 -10
  47. package/dist/server/src/controllers/settingsController.d.ts +2 -1
  48. package/dist/server/src/controllers/userController.d.ts +1 -0
  49. package/dist/server/src/index.d.ts +195 -36
  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/index.d.ts +2 -11
  54. package/dist/server/src/routes/settingsRoutes.d.ts +1 -1
  55. package/dist/server/src/services/autoLinkService.d.ts +29 -0
  56. package/dist/server/src/services/emailService.d.ts +32 -0
  57. package/dist/server/src/services/firebaseService.d.ts +97 -13
  58. package/dist/server/src/services/firebaseStrapiLinkService.d.ts +34 -0
  59. package/dist/server/src/services/firebaseUserDataService.d.ts +26 -0
  60. package/dist/server/src/services/index.d.ts +91 -16
  61. package/dist/server/src/services/settingsService.d.ts +55 -0
  62. package/dist/server/src/services/templateService.d.ts +21 -0
  63. package/dist/server/src/services/userService.d.ts +2 -1
  64. package/dist/server/src/templates/defaults/index.d.ts +2 -0
  65. package/dist/server/src/templates/defaults/magic-link.d.ts +2 -0
  66. package/dist/server/src/templates/defaults/password-reset.d.ts +2 -0
  67. package/dist/server/src/templates/types.d.ts +30 -0
  68. package/dist/server/src/utils/fetch-me.d.ts +2 -10
  69. package/dist/server/src/utils/get-user-by-id.d.ts +1 -5
  70. package/dist/server/src/utils/users.d.ts +14 -0
  71. package/package.json +35 -24
  72. package/dist/_chunks/App-B2LtHk9g.js +0 -5062
  73. package/dist/_chunks/App-B3HcVa5j.mjs +0 -5081
  74. package/dist/_chunks/index-CALp4X47.mjs +0 -110
  75. package/dist/_chunks/index-CrGRt-Ya.mjs +0 -191
  76. package/dist/_chunks/index-DMBPEFUy.js +0 -109
  77. package/dist/_chunks/index-DmTKNKJB.js +0 -191
  78. package/dist/admin/src/components/SearchURLQuery/SearchURLQuery.d.ts +0 -18
  79. package/dist/admin/src/components/UserManagement/ResetPassword.d.ts +0 -8
  80. package/dist/server/src/routes/content-internal-api.d.ts +0 -11
  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,555 @@
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` - Authenticated password change (requires JWT)
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
106
+
107
+ Generate a secure 32+ character encryption key for storing Firebase credentials:
108
+
109
+ ```bash
110
+ # Generate a random key (save this!)
111
+ node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
112
+ ```
113
+
114
+ **Common Mistake:** Using a weak or short key. The key MUST be at least 32 characters.
115
+
116
+ ---
25
117
 
26
- ### Via Command Line
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:
27
134
 
28
135
  ```bash
29
- yarn add @meta-cto/strapi-plugin-firebase-auth
136
+ FIREBASE_JSON_ENCRYPTION_KEY=your-generated-key-from-step-2
30
137
  ```
31
138
 
32
- Once the installation is complete, you must rebuild your Strapi instance. You can do this with the following commands:
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:**
151
+
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:
40
157
 
41
- ```bash
42
- yarn develop --watch-admin
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
+ ---
196
+
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.
62
208
 
63
- "firebase-auth": {
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):
73
276
 
74
- ### Step 2: Firebase Configuration Encryption and Integration with Strapi
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)
75
282
 
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.
283
+ ## API Reference
77
284
 
78
- #### Step 1: Obtain Firebase Service Account Key
285
+ ### Public Endpoints
79
286
 
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.
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` | Authenticated password change (requires JWT) |
293
+ | POST | `/api/firebase-authentication/requestMagicLink` | Request passwordless login email |
294
+ | GET | `/api/firebase-authentication/config` | Get public configuration |
81
295
 
82
- #### Step 2: Submit Service Account Key in Strapi Settings
296
+ ### Password Reset Flow
83
297
 
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.
298
+ There are two distinct password reset approaches in this plugin:
85
299
 
86
- This service account key is essential for proper authentication with Firebase. It contains the necessary credentials for your Firebase project.
300
+ #### 1. Forgot Password Flow (Email-Based)
87
301
 
88
- #### Step 3: Save Changes
302
+ **For users who forgot their password:**
89
303
 
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.
304
+ 1. User requests reset: `POST /api/firebase-authentication/forgotPassword` with `{ "email": "user@example.com" }`
305
+ 2. Firebase sends email with link to Firebase's hosted password reset page
306
+ 3. User clicks link Opens Firebase's secure hosted UI
307
+ 4. User enters new password on Firebase's page
308
+ 5. After success → Redirects to configured continue URL
309
+ 6. User logs in normally with new password
93
310
 
94
- ### Step 4 - Rebuild Admin Panel
311
+ **Configuration:** Set `passwordResetUrl` in Firebase Authentication settings (this is where users land AFTER resetting their password on Firebase's page).
95
312
 
96
- After configuring the plugin, rebuild the Strapi admin panel:
313
+ #### 2. Authenticated Password Change
97
314
 
98
- ```bash
99
- npm run build
100
- ```
315
+ **For admin-initiated resets or users changing their own password:**
316
+
317
+ - **Endpoint:** `POST /api/firebase-authentication/resetPassword`
318
+ - **Requires:** Valid JWT in `Authorization` header + `{ "password": "newpassword" }` in body
319
+ - **Use cases:**
320
+ - Admin resetting a user's password via admin panel
321
+ - Authenticated user changing their own password
322
+ - **Returns:** Updated user object + fresh JWT for auto-login
323
+
324
+ **Note:** This endpoint is NOT part of the forgot password email flow. Use `forgotPassword` for email-based password reset.
101
325
 
102
- Alternatively, you can simply delete the existing `./build` directory.
326
+ ### Admin Endpoints
103
327
 
104
- ### Step 5 - Grant Public Permissions
328
+ Admin endpoints use the admin API type (no `/api` prefix) and require admin authentication.
105
329
 
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.
330
+ **User Management:**
331
+ | Method | Endpoint | Purpose |
332
+ |--------|----------|---------|
333
+ | GET | `/firebase-authentication/users` | List/search users |
334
+ | POST | `/firebase-authentication/users` | Create user |
335
+ | GET | `/firebase-authentication/users/:id` | Get user |
336
+ | PUT | `/firebase-authentication/users/:id` | Update user |
337
+ | DELETE | `/firebase-authentication/users/:id` | Delete user |
338
+ | PUT | `/firebase-authentication/users/resetPassword/:id` | Reset password |
109
339
 
110
- That's it! You're ready to use Firebase Authentication in your Strapi project. Enjoy! 🎉
340
+ **Settings Management:**
341
+ | Method | Endpoint | Purpose |
342
+ |--------|----------|---------|
343
+ | GET | `/firebase-authentication/settings/firebase-config` | Get Firebase config |
344
+ | POST | `/firebase-authentication/settings/firebase-config` | Upload Firebase config |
345
+ | DELETE | `/firebase-authentication/settings/firebase-config` | Delete Firebase config |
346
+ | POST | `/firebase-authentication/settings/password-config` | Update password/magic link settings |
347
+
348
+ ---
111
349
 
112
350
  ## Usage
113
351
 
114
- ### Handling User Information
352
+ **Basic Flow:**
115
353
 
116
- To ensure proper handling of user information, make sure to include the following fields in the user object:
354
+ 1. User authenticates with Firebase Client SDK
355
+ 2. Client gets Firebase ID token
356
+ 3. Client sends token to Strapi: `POST /api/firebase-authentication`
357
+ 4. Plugin returns Strapi JWT for API access
117
358
 
118
- - `firebaseUserID` is the field that maps firebase user object to strapi user object.
359
+ **Example (JavaScript):**
119
360
 
120
- These fields can be populated during the creation of the user object if `profileMetaData` is provided.
361
+ ```javascript
362
+ // After Firebase authentication
363
+ const idToken = await firebaseUser.getIdToken();
364
+
365
+ // Exchange with Strapi
366
+ const response = await fetch("https://your-api.com/api/firebase-authentication", {
367
+ method: "POST",
368
+ headers: { "Content-Type": "application/json" },
369
+ body: JSON.stringify({ idToken }),
370
+ });
121
371
 
122
- - `firstName`
123
- - `lastName`
124
- - `phoneNumber`
125
- - `email`
372
+ const { user, jwt } = await response.json();
373
+ localStorage.setItem("jwt", jwt); // Use this JWT for Strapi API calls
374
+ ```
126
375
 
127
- #### Using `firebase-auth` Endpoint
376
+ **Resources:**
128
377
 
129
- When interacting with the `firebase-auth` endpoint, use the following JSON structure in the request body:
378
+ - [Firebase Web SDK](https://firebase.google.com/docs/auth/web/start)
379
+ - [Firebase iOS SDK](https://firebase.google.com/docs/auth/ios/start)
380
+ - [Firebase Android SDK](https://firebase.google.com/docs/auth/android/start)
130
381
 
131
- ```json
132
- {
133
- "idToken": "{{idToken}}",
134
- "profileMetaData": {
135
- "firstName": "name",
136
- "lastName": "name",
137
- "email": "email@gmail.com",
138
- "phoneNumber": "+100000000"
382
+ ---
383
+
384
+ ## Architecture
385
+
386
+ 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.
387
+
388
+ **Security:**
389
+
390
+ - Firebase service account JSON encrypted with AES-256
391
+ - All tokens validated server-side via Firebase Admin SDK
392
+ - Passwords managed by Firebase (not Strapi)
393
+ - User responses automatically sanitized
394
+
395
+ ## Troubleshooting
396
+
397
+ ### 🔴 "Firebase is not initialized"
398
+
399
+ **Solution:**
400
+
401
+ 1. Verify `FIREBASE_JSON_ENCRYPTION_KEY` in `config/plugins.js` (min 32 characters)
402
+ 2. Upload Firebase service account JSON: **Settings → Firebase Authentication**
403
+ 3. Restart Strapi: `yarn develop`
404
+ 4. Check startup logs for initialization errors
405
+
406
+ ---
407
+
408
+ ### 🔴 "Token validation failed"
409
+
410
+ **Solution:**
411
+
412
+ 1. Ensure token hasn't expired (1 hour TTL) - client should obtain fresh token
413
+ 2. Verify client and server use the same Firebase project
414
+ 3. Confirm service account JSON matches your Firebase project ID
415
+ 4. Check Firebase Console for service status
416
+
417
+ ---
418
+
419
+ ### 🔴 Email Not Sending
420
+
421
+ **Solution:**
422
+
423
+ Install and configure Strapi Email Plugin:
424
+
425
+ ```bash
426
+ yarn add @strapi/provider-email-sendgrid
427
+ ```
428
+
429
+ ```javascript
430
+ // config/plugins.js
431
+ email: {
432
+ config: {
433
+ provider: 'sendgrid',
434
+ providerOptions: { apiKey: env('SENDGRID_API_KEY') },
435
+ settings: {
436
+ defaultFrom: 'noreply@yourapp.com'
437
+ }
139
438
  }
140
439
  }
141
440
  ```
142
441
 
143
- These values will be utilized only when the user does not exist and will be ignored in other cases.
442
+ Alternative: Install [Firebase Email Extension](https://extensions.dev/extensions/firebase/firestore-send-email)
144
443
 
145
- #### Hint for strapiKMM SDK Users
444
+ ---
146
445
 
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.
446
+ **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
447
 
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.
448
+ ## Best Practices
150
449
 
151
- ### Client Links and Token Retrieval
450
+ - Use Firebase SDK for authentication (not `emailLogin` for production)
451
+ - Store JWTs in httpOnly cookies (production) or secure storage (mobile)
452
+ - Configure Strapi Email Plugin (SendGrid, Mailgun, SES) for production
453
+ - Implement rate limiting on public endpoints
454
+ - Enforce HTTPS for password reset URLs
455
+ - Monitor Firebase quotas regularly
456
+ - Keep dependencies updated
152
457
 
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:
458
+ ---
155
459
 
156
- - **Android Firebase Setup:**
157
- [Link](https://firebase.google.com/docs/android/setup)
460
+ ## Support
158
461
 
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._
462
+ ### Questions and Issues
161
463
 
162
- - **iOS Firebase Setup:**
163
- [Link](https://firebase.google.com/docs/ios/setup)
464
+ If you encounter problems or have questions:
164
465
 
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._
466
+ 1. **Check Troubleshooting Section:** Review common errors above
467
+ 2. **Firebase Documentation:** [firebase.google.com/docs/auth](https://firebase.google.com/docs/auth)
468
+ 3. **Strapi Documentation:** [docs.strapi.io](https://docs.strapi.io)
469
+ 4. **GitHub Issues:** [github.com/meta-cto/strapi-plugin-firebase-auth/issues](https://github.com/meta-cto/strapi-plugin-firebase-auth/issues)
470
+ - Search existing issues first
471
+ - Provide detailed information when creating new issues
167
472
 
168
- - **Web Firebase Setup:**
169
- [Link](https://firebase.google.com/docs/web/setup)
473
+ ### Creating a Bug Report
170
474
 
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._
475
+ When reporting issues, please include:
174
476
 
175
- ## Client setup
477
+ 1. **Plugin version:** Check `package.json`
478
+ 2. **Strapi version:** Run `yarn strapi version`
479
+ 3. **Node version:** Run `node --version`
480
+ 4. **Error message:** Full error text and stack trace
481
+ 5. **Steps to reproduce:** Detailed steps to trigger the issue
482
+ 6. **Configuration:** Relevant plugin configuration (redact sensitive data)
483
+ 7. **Expected behavior:** What should happen
484
+ 8. **Actual behavior:** What actually happens
176
485
 
177
- **Android Sample:**
486
+ ### Feature Requests
178
487
 
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:
488
+ To request new features:
183
489
 
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
- ```
490
+ 1. Search existing feature requests
491
+ 2. Create detailed proposal with use case
492
+ 3. Explain why feature would be beneficial
493
+ 4. Suggest implementation approach (if applicable)
198
494
 
199
- **iOS Sample:**
495
+ ### Community
200
496
 
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
497
+ - **GitHub Discussions:** Ask questions and share experiences
498
+ - **Discord:** Join Strapi community Discord server
499
+ - **Stack Overflow:** Tag questions with `strapi` and `firebase`
204
500
 
205
- - Sample Code:
501
+ ---
206
502
 
207
- ```swift
208
- guard let clientID = FirebaseApp.app()?.options.clientID else { return }
503
+ ## License
209
504
 
210
- // Create Google Sign In configuration object.
211
- let config = GIDConfiguration(clientID: clientID)
212
- GIDSignIn.sharedInstance.configuration = config
505
+ This plugin is licensed under the MIT License. See `LICENSE.md` for full details.
213
506
 
214
- // Start the sign in flow!
215
- GIDSignIn.sharedInstance.signIn(withPresenting: self) { [unowned self] result, error in
216
- guard error == nil else {
217
- // ...
218
- }
507
+ ---
219
508
 
220
- guard let user = result?.user,
221
- let idToken = user.idToken?.tokenString
222
- else {
223
- // ...
224
- }
509
+ ## Changelog
225
510
 
226
- let credential = GoogleAuthProvider.credential(withIDToken: idToken,
227
- accessToken: user.accessToken.tokenString)
511
+ See `CHANGELOG.md` for version history and release notes.
228
512
 
229
- // ...
513
+ ---
230
514
 
231
- Auth.auth().signIn(with: credential) { result, error in
515
+ ## Credits
232
516
 
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
- }
517
+ Developed and maintained by **Meta CTO** team.
236
518
 
519
+ **Contributors:**
237
520
 
238
- }
239
- ```
521
+ - Firebase Admin SDK: Google
522
+ - Strapi Framework: Strapi Solutions SAS
523
+ - AES Encryption: crypto-js library
240
524
 
241
- **Web Sample:**
525
+ ---
242
526
 
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:
527
+ ## Additional Resources
247
528
 
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
- ```
529
+ **Firebase Documentation:**
530
+
531
+ - [Firebase Authentication](https://firebase.google.com/docs/auth)
532
+ - [Firebase Admin SDK](https://firebase.google.com/docs/admin/setup)
533
+ - 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
534
 
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
535
+ **Strapi Documentation:**
276
536
 
277
- **For More Samples:**
537
+ - [Strapi v5](https://docs.strapi.io/dev-docs/intro)
538
+ - [Email Providers](https://market.strapi.io/providers) (SendGrid, Mailgun, Amazon SES)
278
539
 
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:
540
+ **Firebase Extensions:**
280
541
 
281
- - [Firebase Official Documentation](https://firebase.google.com/docs/)
542
+ - [Trigger Email Extension](https://extensions.dev/extensions/firebase/firestore-send-email)
282
543
 
283
- **Short Links to Specific Authentication Methods:**
544
+ ---
284
545
 
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.
546
+ **Thank you for using Strapi Plugin Firebase Authentication!** 🎉
287
547
 
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)
548
+ If you find this plugin helpful, please consider:
291
549
 
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)
550
+ - Starring the GitHub repository
551
+ - Sharing with your community
552
+ - Contributing improvements
553
+ - Reporting issues to help us improve
296
554
 
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.
555
+ Happy coding! 🚀