1 | initial version |
To use Node.js with Firebase to generate a new user, follow these steps:
npm install firebase-admin firebase --save
const admin = require('firebase-admin');
const serviceAccount = require('/path/to/serviceAccountKey.json');
const firebaseConfig = require('/path/to/firebaseConfig.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: firebaseConfig.databaseURL
});
async function createNewUser(email, password) {
try {
const userRecord = await admin.auth().createUser({
email: email,
password: password,
});
console.log('Successfully created new user:', userRecord.uid);
return userRecord;
} catch (error) {
console.error('Error creating new user:', error);
return null;
}
}
const email = 'testuser@example.com';
const password = 'examplepassword';
createNewUser(email, password)
.then((userRecord) => {
// Handle successful user creation
})
.catch((error) => {
// Handle error on user creation
});
This will create a new user with the specified email and password in your Firebase project.