Skip to content

Instantly share code, notes, and snippets.

@urakozz
Created October 7, 2020 16:11
Show Gist options
  • Save urakozz/b3436ac0a31a20abc8495bc7a6ca416a to your computer and use it in GitHub Desktop.
Save urakozz/b3436ac0a31a20abc8495bc7a6ca416a to your computer and use it in GitHub Desktop.
Export/import firebase users from one account to another
const admin = require("firebase-admin");
const serviceAccountOld = require("./../../.serviceAccountKey.json");
const serviceAccountNew = require("./../../.serviceAccountKey-new.json");
const appOld = admin.initializeApp({
credential: admin.credential.cert(serviceAccountOld),
databaseURL: "https://old.firebaseio.com",
}, "old");
const appNew = admin.initializeApp({
credential: admin.credential.cert(serviceAccountNew),
databaseURL: "https://new.firebaseio.com",
}, "new");
appOld.auth().listUsers().then(data => {
console.log(data.users.length, "users")
const converted = data.users.map(user => ({
...user,
passwordHash: Buffer.from(user.passwordHash),
passwordSalt: Buffer.from(user.passwordSalt),
}));
return appNew.auth().importUsers(converted, {
hash: {
algorithm: 'SHA1',
rounds: 1
}
})
}).then((res) => {
console.log("imported")
console.log(res)
process.exit(0)
}).catch(e => {
console.log(e);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment