简体   繁体   English

ember.js和firebase - 无法注册用户

[英]ember.js and firebase - unable to sign up user

I'm trying to get a user sign up working on my ember app using firebase as the backend. 我正在尝试使用firebase作为后端让用户注册我的ember应用程序。 I'm using the torii add-on for user authentication and am just trying to test it out. 我正在使用torii插件进行用户身份验证,我只是想测试一下。 However when I try to sign up a user I get the following error: Uncaught TypeError: n.default is not a constructor 但是,当我尝试注册用户时,我收到以下错误: Uncaught TypeError: n.default is not a constructor

This is how my route looks at routes/index.js : 这是我的路线看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 : 我在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. 我几乎遵循了这个指南: http//vikram-s-narayan.github.io/blog/authentication-with-ember-and-firebase-part-2/ ,除了我只关注注册并将其全部放在索引中以简化。

Problem was I'm using the Firebase 3.0 SDK but using code for a previous version. 问题是我使用的是Firebase 3.0 SDK,但使用的是以前版本的代码。 Moved the code into my controller and updated it to use createUserWithEmailAndPassword : 将代码移动到我的控制器并更新它以使用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();
        });
      }
    }   

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM