Ionic.io Users Auth Service issue - Imposible getting started ;(


#1

Hi,

I am new to ionic and I am not JavaScript pro.
I have some issues getting started implementing Membership using ionic.io Users.
Initially I developed my app with Firebase Auth and it was working well but then I wanted to change the Membership to Ionic Users in order
to easily send push notifications to specified users.

There is very superficial documentation on how to implement Register, Login, Password Reset … using ionic.io. and I don’t find any video tutorial or complete comprehensive tutorial using ionic.io Users Auth services.

I try to register and login the user in one step but it’s not work.
Maybe you can take a look and help me with this.
I call registerUser method from the register form and I get a new user created in the ionic.io users dashboard but I can’t login it immediately.

This is may log:

authCtrl.js:132 userWasRegsitred called
authCtrl.js:105 tryToAuthenticateAfterRegister called 
authCtrl.js:43 authenticatedAfterRegister was called
authCtrl.js:72 User NOT authenticated after login
ionic.io.bundle.min.js:2 Ionic User: loaded user

This is my code:

$scope.registerUser = function (authUser) {

  $scope.showLoading();


   var userDetails = {
     email:        authUser.email,
     password:     authUser.password,
   }

   userDetails.custom = {
     displayName:  authUser.displayName,
     provider: authProvider,
     device: ionic.Platform.device(),
   };

   Ionic.Auth.signup(userDetails).then(userWasRegsitred(userDetails), signupFailure);

}


   var userWasRegsitred = function(userDetails) {

     tryToAuthenticateAfterRegister(userDetails);

}


var tryToAuthenticateAfterRegister = function (userDetails) {

      Ionic.Auth.login(authProvider, authSettings, userDetails)
        .then(authenticatedAfterRegister(userDetails), failedAuthenticatedAfterRegister);

}


var failedAuthenticatedAfterRegister = function () {

  console.log('failedAuthenticatedAfterRegister was called')

}



var authenticatedAfterRegister = function (userDetails) {

  // Double check if user was logged in

   var user = Ionic.User.current();

    if (user.isAuthenticated()) {

    // user is logged in

      console.log('User authenticated after authenticatedAfterRegister called')

    // Add custom details to the new user

      user.set('_created', time() );
      user.set('_isBrandNew', true);
      user.save();

      $scope.hideLoading();
      $state.go(‘dashboard');


    } else {

    // user is NOT logged in

      console.log('User NOT authenticated after authenticatedAfterRegister called');

    }

}

Maybe somebody can help.

Thanks.


#2

I’m trying as well to do this implementation and agree with @cardei on the fact there’s not enough information =/


#3

Have you run: ionic add ionic-platform-web-client ?


#4

I am currently having the same issue and was wondering if anyone has found anymore information about creating a simple user authentication system with ionic.io


#5

having the same problem here
i can’t find any tutorial that will explain things step by step …
the ionic documentation is too general


#6

The ionic creator team developed this great video on how to gets started with Ionic Auth. It helped me quite a bit: