dark.o
dark.o

Reputation: 35

The email address is badly formatted firebase vue.js

Getting an error "The email address is badly formatted." when trying to use Vue.js with firebase to create a login page.

Here's my code:

<template>
    <div class = "sign-up">
        <p> Let's create a new account</p>
        <input type="email" v-model="email" placeholder="Email"> <br>
        <input type="password" v-model="password" placeholder="Password"> <br>
        <button v-on:click="signUp">Sign Up</button>
        <br>

    </div>

</template>


<script> 

import firebase from 'firebase'

      export default {
    name:'Signup',
    data: function() {
      return {
        email: '',
        password: '',
      }
    },
    methods: {
        signUp: function() {

            firebase.auth().createUserWithEmailAndPassword(this.email, this.password).then(

                function (user) {
                    alert('Your account has been created')
                },
                function(error) {

                   var errorCode = error.code;
                   var errorMessage = error.message;

                   if (errorCode == 'auth/weak-password') {
                       alert('The password is too weak.');
                  } else {
                       alert(errorMessage);
                      }
                    console.log(error);

                 });
        }

    }

  }



</script>

I did make sure that I have enabled the authentication part at the firebase console .

Don't know why still get this error

Help please

Upvotes: 0

Views: 1976

Answers (2)

Sangey lama
Sangey lama

Reputation: 11

This works well. I tired to solve your ones. I have brought official firebase auth sample. Your user was not defined and while importing you must have use {} to prevent .auth() error.

       <template>
        <div class = "sign-up">
            <p> Let's create a new account</p>
            <input type="email" v-model="email" placeholder="Email"> 
            <input type="password" v-model="password" placeholder="Password">
            <button v-on:click="signUp">Sign Up</button>
    
        </div>
    </template>
    
    
    <script> 
    
    import {fb} from '../firebase';
    
          export default {
        name:'Signup',
        data() {
          return {
            email: "",
            password: "",
          }
        },
        methods: {
            signUp: function() {
                fb.auth().createUserWithEmailAndPassword(this.email, this.password)
                        .catch(function(error) {
                    // Handle Errors here.
                    var errorCode = error.code;
                    var errorMessage = error.message;
                    if (errorCode == 'auth/weak-password') {
                        alert('The password is too weak.');
                    } else {
                        alert(errorMessage);
                    }
                    console.log(error);
                    });    
            }
    
        }
    
      }
    
    
    
    </script>

Upvotes: 1

dark.o
dark.o

Reputation: 35

Thank God I solved it.

The problem is solved by adding

 firebase.initializeApp(config);

right after

import firebase from 'firebase'

since I have already initialize Firebase in other files

the problem might be caused by javascript loading asynchronously .

Upvotes: 1

Related Questions