Last active
July 12, 2017 22:16
-
-
Save harrylincoln/dc18b94ab4409fe2f1bb7add3b18fdfe to your computer and use it in GitHub Desktop.
Express route for creating user via firebase admin
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
const express = require('express'); | |
const router = express.Router(); | |
const admin = require('firebase-admin'); | |
const db = admin.database(); | |
... | |
router.use('/create-user', (req, res) => { | |
console.log('createUser: req', req.body); | |
admin.auth().createUser({ | |
email: req.body.emailAddress, | |
emailVerified: false, | |
password: req.body.pass, | |
displayName: "Harry Lincoln" | |
}) | |
.then(function(userRecord) { | |
// See the UserRecord reference doc for the contents of userRecord. | |
console.log("Successfully created new user:", userRecord); | |
console.log("Continuing to set new stuff..."); | |
const ref = db.ref("users"); | |
ref.child(userRecord.uid).set({ | |
displayName: userRecord.displayName, | |
test: 'test', | |
age: 28, | |
occupation: 'frontend dev', | |
hobbies: ['photography', 'coding', 'music'] | |
}); | |
res.json({ | |
message: 'Completed BE task, user record updated', | |
user: userRecord | |
}); | |
console.log("Finished setting new stuff"); | |
}) | |
.catch(function(error) { | |
console.log("Error creating new user:", error); | |
}); | |
}); | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment