Jalasem Jalasem - 1 year ago 149
Javascript Question

Can't Sign up with firebase

I am trying to create a sign up form with firebase and login as well, I have tried so many things but it won't work. I keep getting this error when I click the signup button which calls the method

auth.createUserWithEmailAndPassword(email, pass)

A network error (such as timeout, interrupted connection or unreachable host) has occurred.

Below here is part of my HTML

<div class="col l7" id="signup">
<div class="form card">
<div class="switch">
<input name="student_" id="student_" type="checkbox">
<span class="lever"></span>
<div class="container">
<input type="text" placeholder="Name" id="signup_fullname">
<input type="text" placeholder="Matric Number/Staff no." id="signup_matric">
<input type="email" placeholder="Email" id="signup_email">
<div class="input-field col s12">
<select id="signup_dept">
<option value="" disabled selected>Select your department</option>
<option value="ics">ICS</option>
<option value="masscomm">Mass Comm.</option>
<option value="lis">Library Science</option>
<option value="tcs">Telecomm Science</option>
<option value="csc">Computer Science</option>
<div class="input-field col s12">
<select id="signup_level">
<option value="" disabled selected>Select your Level</option>
<option value="100">100 Level</option>
<option value="200">200 Level</option>
<option value="300">300 Level</option>
<option value="400">400 Level</option>
<option value="500">500 Level</option>
<div class="input-field col s12">
<select id="signup_religion">
<option value="" disabled selected>Select your religion</option>
<option value="1">Islam</option>
<option value="2">Christianity</option>
<input type="password" placeholder="password" id="signup_password">
<!--<input type="password" placeholder="Confirm password" id="signup_confirm_password">-->
<button class="btn-large second-color" id="btnSignUp">signup</button></a>

and my JS code

readystatemode = false;
(function () {
var config = {
apiKey: "<my API key>",
authDomain: "<my auth domain>",
databaseURL: "<my database url>",
storageBucket: "<my storage bucket url>",

// Get Elements
var student_ = document.getElementById('student_'); // check whether is a student or staff; expect on or off
var student__;
if (student_.value == "on") {
student__ = "student";
} else {
student__ = "staff";
var signup_fullname = document.getElementById('signup_fullname');
var signup_matric = document.getElementById('signup_matric');
var signup_email = document.getElementById('signup_email');
var signup_dept = document.getElementById('signup_dept');
var signup_level = document.getElementById('signup_level');
var signup_religion = document.getElementById('signup_religion');
var signup_password = document.getElementById('signup_password');
var login_email = document.getElementById('login_email');
var login_password = document.getElementById('login_password');
// buttons
var btnLogin = document.getElementById("btnLogin");
var btnSignUp = document.getElementById("btnSignUp");

// signup event
btnSignUp.addEventListener('click', e => {
// Get Email and pass
//TODO: check for real emails
console.log("just clicked the signup button");

var email = signup_email.value;
var pass = signup_password.value;
var auth = firebase.auth();
// sign up
const promise = auth.createUserWithEmailAndPassword(email, pass);
.catch(e => console.log(e.message));

if (auth.currentUser != null) {
displayName: signup_fullname,
userCategory: student__,
matric: signup_matric,
department: signup_dept,
level: signup_level,
religion: signup_religion
}).then(function () {
console.log("update successful");
window.readystatemode = true;
}, function (error) {
console.log("update failed");

firebase.auth().onAuthStateChanged(firebaseUser => {
if (firebaseUser && window.readystatemode) {
} else {
console.log("not logged in");


Answer Source

I had the same problem too The way I solved it was to add the domain where the firebase app is hosted on the firebase console

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download