0

I'm following a tutorial of Vue.js with Firebase.

I'm novice to this and trying to make user account to firebase with Vue.js and I'm getting this error.

Uncaught O {code: "auth/argument-error", message: "createUserWithEmailAndPassword failed: First argument "email" must be a valid string."}

I've already enabled sign-in-method in firebase. Here is my code.

<template>
  <div class="signup">
    <p>Let's create a new account</p>
    <input type="text" v-model="email" placeholder="Email" /><br/>
    <input type="password" v-model="password" placeholder="Password" /><br/>
    <button v-on:click="signUp">Sign up</button>
    <span>or go back to <router-link to="/login">login</router-link>.</span>
  </div>
</template>

<script>
import firebase from 'firebase'

export default {
  name: 'signup',
  data () {
    return {
      email: '',
      password: ''
    }
  },
  methods: {
    signUp: () => {
      firebase.auth().createUserWithEmailAndPassword(this.email, this.password).then(
        (user) => {
          alert('Your account has been created!')
        },
        (err) => {
          alert('Opps!' + err.message)
        }
      );
    }
  }
}
</script>

When I console.log the email and password in signUp method, I found both the email and password are undefined.

WaiLin
  • 161
  • 1
  • 2
  • 15
  • Possible duplicate of [VueJS: why is "this" undefined?](https://stackoverflow.com/questions/43929650/vuejs-why-is-this-undefined) – Eric Guan Oct 25 '17 at 05:46
  • Thanks @EricGuan so the problem was arrow functions. It works now. – WaiLin Oct 25 '17 at 06:06

1 Answers1

0

The Problem was arrow functions. Changed ()=> {} to function() {} and now it works. Thanks to @EricGuan's comment.

WaiLin
  • 161
  • 1
  • 2
  • 15