Created
May 8, 2025 09:17
-
-
Save rahulvramesh/b54ea806ab251f74d2851e293e3602e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize the Firebase Admin SDK (replace with your actual initialization) | |
// For example: | |
const admin = require("firebase-admin"); | |
const serviceAccount = require("./serviceAccountKey.json"); | |
admin.initializeApp({ | |
credential: admin.credential.cert(serviceAccount), | |
//databaseURL: 'https://your-database-name.firebaseio.com' | |
}); | |
// Assuming you have already initialized the Admin SDK and have access to the auth service | |
const { getAuth } = require("firebase-admin/auth"); | |
// Up to 1000 users can be imported at once. | |
const userImportRecords = [ | |
{ | |
uid: "uid1", | |
email: "[email protected]", | |
passwordHash: Buffer.from("password-hash"), | |
}, | |
{ | |
uid: "uid2", | |
email: "[email protected]", | |
passwordHash: Buffer.from("password-hash"), | |
}, | |
// Add more user records here, up to 1000 | |
]; | |
getAuth() | |
.importUsers(userImportRecords, { | |
hash: { | |
algorithm: "BCRYPT", | |
}, | |
}) | |
.then((userImportResult) => { | |
// The number of successful imports is determined via: userImportResult.successCount. | |
// The number of failed imports is determined via: userImportResult.failureCount. | |
console.log( | |
`Successfully imported ${userImportResult.successCount} users.` | |
); | |
console.log(`Failed to import ${userImportResult.failureCount} users.`); | |
// To get the error details. | |
userImportResult.errors.forEach((indexedError) => { | |
// The corresponding user that failed to upload. | |
console.log( | |
"Error " + indexedError.index, | |
" failed to import: ", | |
indexedError.error | |
); | |
}); | |
}) | |
.catch((error) => { | |
// Some unrecoverable error occurred that prevented the operation from running. | |
console.error("Error importing users:", error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment