Last active
May 29, 2025 21:04
-
-
Save faustoct1/89a0ce5e7b156bc4d2af55540072142d to your computer and use it in GitHub Desktop.
restore deleted firebase auth entry
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
/* | |
you need to have the user collection with id or smth, | |
them replace id with the user_id and the fields like name, photo, etc | |
fields to replace: uid, email, displayName, photoURL. | |
run this script: node restore-auth-firebase.js | |
*/ | |
const admin = require('firebase-admin') | |
const serviceAccount = require("./key.json") | |
admin.initializeApp({ | |
credential: admin.credential.cert(serviceAccount) | |
}) | |
;(async ()=>{ | |
admin.auth().importUsers([ | |
{ | |
uid: 'some-uid', | |
displayName: 'user name', | |
email: '[email protected]', | |
photoURL: 'photo url', | |
emailVerified: true, | |
// Set this user as admin. | |
customClaims: { admin: false }, | |
// User with Google provider. | |
providerData: [ | |
{ | |
uid: 'some-uid', | |
email: '[email protected]', | |
displayName: 'username', | |
photoURL: 'photo url', | |
providerId: 'google.com', | |
}, | |
], | |
}, | |
]) | |
.then((results) => { | |
console.log(results) | |
results.errors.forEach((indexedError) => { | |
console.log(indexedError) | |
console.log(`Error importing user ${indexedError.index}`); | |
}); | |
}) | |
.catch((error) => { | |
console.log('Error importing users :', error); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment