Firebase Extension for any Firebase project that automatically backs up the Authentication users' data to a Google Cloud Storage bucket on a predefined schedule.
Author: Foo Jen Sean (www.foojensean.com)
Description: Automatically backs up Firebase Authentication users to a Google Cloud Bucket on a predefined schedule.
This extension simplifies the process of regularly backing up Firebase Authentication users' data. By automatically creating backups at a specified interval, this extension provides an extra layer of security and ensures data recoverability for your Firebase project.
This extension regularly backs up user data from Firebase Authentication. It captures user details such as unique identifiers (UIDs), email addresses, custom claims, and more. These backups can be vital for disaster recovery, auditing, and analysis purposes. The backups are in JSON format and are stored in a Google Cloud Storage bucket. You can configure the extension to run at a specified interval, such as daily or weekly. The backups can be easily imported into a Firebase project using the Firebase Admin SDK.
To install this extension for your Firebase project, you can install it via the Firebase Extensions Hub.
The extension runs automatically based on your configured schedule. There is no need for manual intervention after setup. Backups are created and stored in the specified Cloud Storage bucket.
TODO: Add instructions for importing users from backups. Possibly create a separate extension for this. This will most likely be a done via a Node.js script that uses the Firebase Admin SDK.
To use this extension, your Firebase project must be on the Blaze (pay as you go) plan due to its use of Firebase and Google Cloud Platform services. Be aware that this extension uses Cloud Storage for backups, which may incur associated charges based on usage.
The extension requires appropriate IAM roles to access and manage resources in your project:
- Firebase Authentication admin: This role is necessary for retrieving user data for backup.
- Storage Admin: This role is necessary for creating backups in Cloud Storage.
Contributions to this extension are welcome! Feel free to submit issues, feature requests, or pull requests to enhance its functionality. See the CONTRIBUTING guide for more information.
All tests are written with Mocha.
The unit tests target the performBackup function in extension/src/index.ts
.
Unit tests can be run locally. It uses fake data and mocks to simulate the Firebase Authentication and Cloud Storage services.
To run the unit tests, run the following command in the extension
folder:
npm run test:unit
To run the integration tests, you first need to set up a Firebase project and install the Firebase CLI. The integration tests are created to test connections to external services such as Firebase Authentication and Cloud Storage.
To run the integration tests, run the following command in the extension
folder:
npm run test:integration
To run the system tests, you first need to set up a Firebase project and install the Firebase CLI.
-
Create a
.env
file inextension/tests/system-tests/configs
with the following contents:PROJECT_ID="<project id>" # Optional: Project ID of the Firebase project to test with, if you want to test with a live project BUCKET_NAME="<bucket name>" CRON_SCHEDULE="<cron schedule>"
You can refer to the
sample.env
file in the same folder for an example. -
Optional: Download a service account key for the Firebase project you want to test with and save it as
extension/tests/configs/serviceAccountKey.json
. This is required if you want to test the extension with a live Firebase project in addition to using the fakes. -
Optional: Run the system tests with the Firebase Emulator Suite by running the below command in the
auth-scheduled-backup
directory. This is required if you want to run the tests that use the Firebase Emulator Suite.firebase emulators:exec "cd extension && npm run test:system"
This project is licensed under the Apache License, Version 2.0. See LICENSE for more information.
If you have any questions or need assistance, you can reach out to me at:
- Email: jenseanfoo@gmail.com
For more information about Firebase Authentication and its features, you can refer to the official Firebase Authentication Documentation.