Created
October 7, 2020 16:11
-
-
Save urakozz/b3436ac0a31a20abc8495bc7a6ca416a to your computer and use it in GitHub Desktop.
Export/import firebase users from one account to another
This file contains 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
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