Firebase auth。$ createUserWithEmailAndPassword抱怨电子邮件格式

时间:2018-02-05 20:24:37

标签: string email firebase vue.js firebase-authentication

在firebase上,使用vue.js,在注册并尝试向数据库添加有关用户的更多信息时,当应用程序尝试将newUser电子邮件写入Firebase时,我遇到了一个非常令人沮丧的错误。当电子邮件是对象的一部分时,应用程序就会中断。

我使用createUserWithEmailAndPassword(this.email,this.password)方法来授权和注册用户(在用户列表上),然后调用一个函数在数据库上注册同一个用户。

这是我得到的错误:

enter image description here

正如您所看到的,控制台正在输出字符串joaoalvesmarrucho@gmail.com,同时抱怨它不是字符串。 :/

我已将电子邮件转换为字符串但未成功。

HTML模板:

<form v-on:submit.prevent>
        <div class="control">
          <input class="input" v-model="newUser.name" type="text" placeholder="Your Display Name">
        </div>
        <div class="control">
          <input class="input"  v-model="newUser.email" id="email" type="email" placeholder="joew@bloggs.com" >
        </div>
        <div class="control">
          <input id="password" v-model="newUser.password" class="input" type="password" placeholder="Password">
        </div>
        <div class="control">
          <input id="confirm_password" class="input" type="password"  placeholder="Retype your password" v-on:keyup="checkRetypePassword">
        </div><span id='message'></span>
        <button type="submit" class="button is-primary" v-on:click="signUp">Register</button><span> or </span><button type="submit" class="button is-primary" v-on:click="googleSignUp">Register with Google</button>
      </form>

SCRIPT:

export default {
  data: function() {
    return {
      users: usersRef,
      // username: this.$store.getters.getUser.displayName,
      newUser: {
        name: '',
        email: '' , 
        password: '',
        uid: '',
        }
    };
  },
methods: {
    signUp: function() {
      var jsonEmail = JSON.stringify(this.newUser.email); 
      var email = jsonEmail.replace(/\"/g, ""); 
      console.log(email);
      firebaseApp.auth().createUserWithEmailAndPassword(this.email, this.password).then(function(user) {
        logUser(user); // callback push user to database
        console.log(email);
      }, function(error) {
        alert(error.message + error.code);
    });
    function logUser(user) { 
      usersRef.push(this.newUser);
      this.name = '';
      this.email = ''; // ERROR: "email" must be a valid string
      this.uid = firebaseApp.auth().currentUser.uid;
    }
你可以给我一个暗示吗?

1 个答案:

答案 0 :(得分:0)

只需从电子邮件字段中获取值即可使用。希望这对未来的某些人有用:

HTML

  Form f = new Form();     
  f.StartPosition = FormStartPosition.CenterParent;
  f.ShowDialog(this);

SCRIPT:

<form v-on:submit.prevent>
        <div class="control">
          <input class="input" v-model="user.name" type="text" placeholder="Your Display Name">
        </div>
        <div class="control">
          <input class="input"  v-model="user.email" id="email" type="email" placeholder="joew@bloggs.com" >
        </div>
        <div class="control">
          <input id="password" v-model="user.password" class="input" type="password" placeholder="Password">
        </div>
        <div class="control">
          <input id="confirm_password" class="input" type="password"  placeholder="Retype your password" v-on:keyup="checkRetypePassword">
        </div><span id='message'></span>
        <button type="submit" class="button is-primary" v-on:click="signUp">Register</button><span> or </span><button type="submit" class="button is-primary" v-on:click="googleSignUp">Register with Google</button>
      </form>