Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.1.1] Validation function ignored when user already logged-in #31

Open
legildas opened this issue Nov 4, 2016 · 2 comments
Open

[1.1.1] Validation function ignored when user already logged-in #31

legildas opened this issue Nov 4, 2016 · 2 comments

Comments

@legildas
Copy link

legildas commented Nov 4, 2016

Hello,

Since angular-meteor-auth 1.1.1, the optional validation function passed to awaitUser is being ignored when the user is already logged-in.

This is due to b7c78da (fixed #25) which introduced a bypass that doesn't use the validation function before resolving :

// If user is already logged in resolve the promise immediately to prevent an
// unnecessary computation
if (this.currentUser) {
    deferred.resolve(this.currentUser);
    // Keep the schema of the promise consistent
    deferred.promise.stop = angular.noop;
    return deferred.promise;
}

I already forked the repo and fixed it locally. Let me know if a PR sounds relevant.

@DAB0mB
Copy link
Collaborator

DAB0mB commented Nov 8, 2016

@gsaynac Did you encounter any specific issue because of it? This was done due to optimizations. Unless you have a reason good enough to revert it I wouldn't rush to do it.

@legildas
Copy link
Author

We are using this validation function feature all over our app's router and I am pretty sure it is partially broken in version 1.1.1, so that's quite an issue.

Take a look at this example from your documentation :

// Usage with validation method
$stateProvider
  .state({
    template: '<my-component></my-component>',
    resolve: {
      user: ($auth) => {
        return $auth.awaitUser((user) => {
          if (user.firstName === 'Uri') {
            return true;
          }
          else {
            return 'You are not Uri!';
          }
        }
      }
    }
  });

As mentioned earlier, in case the user is already logged-in, the validation method is not taken into account anymore. This means that $awaitUser's promise will be fulfilled no matter if user.firstName === 'Uri' is true or not. In other words : this example simply won't work.

Concerning the optimisations, I was not talking about reverting it. I actually separated the validation mechanism from the rest of the logic then called it the same way you did in your fix : outside the autorun block if user is already logged-in (to prevent an unnecessary computation, as you said) and inside the autorun block otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants