Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49076

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

$
0
0

@cardei wrote:

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.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49076

Trending Articles