ember.js and firebase - unable to sign up user

206 Views Asked by At

I'm trying to get a user sign up working on my ember app using firebase as the backend. I'm using the torii add-on for user authentication and am just trying to test it out. However when I try to sign up a user I get the following error: Uncaught TypeError: n.default is not a constructor

This is how my route looks at routes/index.js:

import Ember from 'ember';
import Firebase from 'firebase';

export default Ember.Route.extend({
  actions: {
    signUp: function(){
      var controller = this.get('controller');
      var firstName = controller.get('firstName');
      var lastName = controller.get('lastName');
      var email = controller.get('email');
      var password = controller.get('password');
      var ref = new Firebase("https://my-app-name.firebaseio.com");
      var _this = this;

    ref.createUser({
      email    : email,
      password : password
      }, 
      function(error, userData){
        if (error) {
          alert(error);
        } else {
          _this.get('session').open('firebase', {
            provider: 'password',
            'email': email,
            'password': password
          }).then(function(){
            var user = _this.store.createRecord('user', {
              id: userData.uid,
              firstName: firstName,
              lastName: lastName
            });

            user.save().then(function(){
              _this.transitionTo('protected');
            });
          });
        }
      });
    }
  }
});

My template at templates/index.hbs:

Signup here: <br>

{{input type="text" value=firstName placeholder="First Name"}}<br>
{{input type="text" value=lastName placeholder="Last Name"}}<br>
{{input type="text" value=email placeholder="Email"}}<br>
{{input type="password" value=password placeholder="Password"}}<br>
<button {{action "signUp"}}> Sign Up </button>

and my user model:

import DS from 'ember-data';

export default DS.Model.extend({
  firstName: DS.attr(),
  lastName: DS.attr()
});

I'm really not sure where I'm going wrong. I've pretty much followed this guide: http://vikram-s-narayan.github.io/blog/authentication-with-ember-and-firebase-part-2/, except I'm just focusing on the sign up and putting it all in the index for simplicity.

1

There are 1 best solutions below

0
On

Problem was I'm using the Firebase 3.0 SDK but using code for a previous version. Moved the code into my controller and updated it to use createUserWithEmailAndPassword:

import Ember from 'ember';

export default Ember.Controller.extend({  
  firebaseApp: Ember.inject.service(),

    actions: {
      signUp() {
        const auth = this.get('firebaseApp').auth();
        auth.createUserWithEmailAndPassword(this.get('email'), this.get('password')).
        then((userResponse) => {
          const user = this.store.createRecord('user', {
            id: userResponse.uid,
            email: userResponse.email
          });
          return user.save();
        });
      }
    }   

});