Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post('/signup', function(err, req, res, next){
- var username = req.body.username;
- var fname = req.body.fname;
- var lname = req.body.lname;
- var email = req.body.email;
- var password = req.body.password;
- database.createUserWithEmailAndPassword(email, password, username, fname, lname);
- //This is causing redirect to 404 page. Want to just stay here.
- if (err){
- alert('Email has already been registered');
- } else {
- res.redirect('/');
- }
- });
- exports.createUserWithEmailAndPassword = function(email, password, username, fname, lname){
- if (!email || !password || !username || !fname || !lname){
- console.log ('email: ' + email);
- console.log ('password: ' + password);
- console.log ('username: ' + username);
- console.log ('fname: ' + fname);
- console.log ('lname: ' + lname);
- throw Error('You are missing information');
- }
- firebase.auth().createUserWithEmailAndPassword(email, password).then(function(user){
- firebase.database().ref('users/' + username).set({
- email: email,
- fname : fname,
- lname : lname
- });
- }).catch(function(error) {
- // Handle Errors here.
- var errorCode = error.code;
- console.log('ERROR CODE: ' + errorCode);
- var errorMessage = error.message;
- console.log('ERROR MESSAGE' + errorMessage);
- throw Error('Unable to save user.')
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement