This Node.js script uses Firebase Admin SDK to retrieve user emails from Firebase Authentication and adds their creation date and last login timestamp to a Firestore database, where the document ID is the user's email. This information can be used for analytics, tracking user engagement, or generating reports.
-
Have a Firebase project with Firebase Authentication enabled.
-
Create a service account for your Firebase project and download the service account key file.
-
Install the Firebase Admin SDK for Node.js by running the following command:
npm install firebase-admin
-
Clone this repository and navigate to the project directory.
-
Copy your service account key file to the project directory.
-
Rename your service account key file to serviceAccountKey.json.
-
Run the script using the following command:
node index.js
The output of the script will be an object containing each user's email address, creation date, and last login timestamp. This object can be used to generate reports, visualize user activity, or integrate with other analytics tools.
Note that this script retrieves all user records, including deleted or disabled users. If you only want to retrieve active users, you can modify the listUsers() method as explained earlier.