0

I am trying to make a registration system, where the user enters their email and password and I am trying to add it to my firebase Database. I have a look at the other answers on here for this question, but the answers are only for a typo and I don't see any typos in my program.

Register.html:

<html ng-app="myApp" lang="en">
   <head>
      <meta charset="UTF-8">
      <title>Title</title>
      <h1>Registration page</h1>
      <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-route.js"></script>
      <!-- AngularFire -->
      <script src="https://cdn.firebase.com/libs/angularfire/2.3.0/angularfire.min.js"></script>
      <script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-app.js"></script>
      <script src="app.js" type="text/javascript"></script>
   </head>
   <body ng-controller="regCtrl">
      <script>
         var config={
             ...
         };
         firebase.initializeApp(config);
      </script>
      <label for="reguser"> Username</label>
      <input ng-model="reguser" placeholder="Enter email" name="reguser" type="email">
      <br>
      <label for="regpass">Password</label>
      <input ng-model="regpass" placeholder="Enter password" name="regpass" type="password">
      <br>
      <button type="button" ng-click="register()">Register</button>
   </body>
</html>

This is the app.js:

var logCtrl = angular.module('logCtrl', []);
var regCtrl = angular.module('regCtrl', ['firebase']);
var app = angular.module('myApp', ['logCtrl', 'regCtrl']);

regCtrl.controller('regCtrl', ['$scope', '$firebase', '$firebaseAuth', function($scope, $firebase, $firebaseAuth) {
  $scope.register = function register() {
    //The line underneath is where the error is pointed to
    var ref = firebase.database().ref("...");
    var auth = $firebaseAuth(ref);
    console.log('button clicks');
    auth.$createUserWithEmailAndPassword(
      $scope.reguser,
      $scope.regpass
    ).then(function(reguser) {
      $scope.message = "Thanks for registering " + $scope.reguser;
    }).catch(function(error) {
      $scope.message = "invalid";
    });
    console.log('it works');
  }
}])
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

0 Answers0