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

Bug when using new strategy #62

Closed
bakura10 opened this issue Jan 15, 2014 · 16 comments
Closed

Bug when using new strategy #62

bakura10 opened this issue Jan 15, 2014 · 16 comments

Comments

@bakura10
Copy link
Contributor

Hi,

I'm trying to use the new strategies branch, however I'm encountering an error:

TypeError: 'null' is not an object (evaluating 'this.get('authenticator').create')

It seems I've followed the example. As JS is not my primary language I'm not sure to be able to spot where the problem comes from.

Thanks!

@marcoow
Copy link
Member

marcoow commented Jan 15, 2014

I pushed a fix for that some hours ago.

Of course the strategies branch isn't released yet so no guarantees for it being ready for production...

Am 15.01.2014 um 12:13 schrieb Michaël Gallego notifications@github.com:

Hi,

I'm trying to use the new strategies branch, however I'm encountering an error:

TypeError: 'null' is not an object (evaluating 'this.get('authenticator').create')

It seems I've followed the example. As JS is not my primary language I'm not sure to be able to spot where the problem comes from.

Thanks!


Reply to this email directly or view it on GitHub.

@bakura10
Copy link
Contributor Author

I'm already using the latest build :). Still have the error :)

@marcoow
Copy link
Member

marcoow commented Jan 15, 2014

Any chance you can give me access to the code or set up a jsbin or so?

Am 15.01.2014 um 12:42 schrieb Michaël Gallego notifications@github.com:

I'm already using the latest build :). Still have the error :)


Reply to this email directly or view it on GitHub.

@bakura10
Copy link
Contributor Author

It's in a private repository, but for now it's a completely empty app.

The initializer:

Ember.Application.initializer({
  name: 'authentication',
  initialize: function(container, application) {
    Ember.SimpleAuth.setup(application);
  }
});

Login controller:

module.exports = App.LoginController = Ember.Controller.extend(Ember.SimpleAuth.AuthenticationControllerMixin);

Login route:

module.exports = App.LoginRoute = Ember.Route.extend();

Application route:

module.exports = App.ApplicationRoute = Ember.Route.extend(Ember.SimpleAuth.ApplicationRouteMixin);

And the login template:

<form {{action authenticate on='submit'}}>
    <div class="control-group">
        <label for="identification">Login</label>
        {{view Ember.TextField id='identification' valueBinding='identification'}}
    </div>

    <div class="control-group">
        <label for="password">Password</label>
        {{view Ember.TextField id='password' type='password' valueBinding='password'}}
    </div>

    <button type="submit">Login</button>
</form>

@marcoow
Copy link
Member

marcoow commented Jan 15, 2014

That’s what was updated earlier today in the examples: you have to mix in
the LoginControllerMixin if you want to use a strategy that takes user
credentials:

module.exports = App.LoginController =
Ember.Controller.extend(Ember.SimpleAuth.LoginControllerMixin);

2014/1/15 Michaël Gallego notifications@github.com

It's in a private repository, but for now it's a completely empty app.

The initializer:

Ember.Application.initializer({
name: 'authentication',
initialize: function(container, application) {
Ember.SimpleAuth.setup(application);
}});

Login controller:

module.exports = App.LoginController = Ember.Controller.extend(Ember.SimpleAuth.AuthenticationControllerMixin);

Login route:

module.exports = App.LoginRoute = Ember.Route.extend();

Application route:

module.exports = App.ApplicationRoute = Ember.Route.extend(Ember.SimpleAuth.ApplicationRouteMixin);

And the login template:

Login {{view Ember.TextField id='identification' valueBinding='identification'}}
Password {{view Ember.TextField id='password' type='password' valueBinding='password'}}
Login


Reply to this email directly or view it on GitHubhttps://github.com//issues/62#issuecomment-32359291
.

Marco Otte-Witte
marco.otte-witte@simplabs.com
http://simplabs.com

@bakura10
Copy link
Contributor Author

Awesome, it works :D. Thanks!

@bakura10
Copy link
Contributor Author

Hi,

I've updated to the latest release (the official release) and now I have the following error:

Uncaught TypeError: Cannot call method 'authenticate' of undefined. It happens in the "authenticate" method of the AuthenticationControllerMixin.

Is this an expected issue?

@bakura10 bakura10 reopened this Jan 20, 2014
@marcoow
Copy link
Member

marcoow commented Jan 20, 2014

No, certainly not expected. Looks like your session is not set. Did you update anything else together with Ember.SimpleAuth?

@bakura10
Copy link
Contributor Author

No, I didn't update anything else. :(.

@marcoow
Copy link
Member

marcoow commented Jan 20, 2014

can you change your login controller to this:

module.exports = App.LoginController = Ember.Controller.extend(Ember.SimpleAuth.LoginControllerMixin, {
  actions: {
    authenticate: function() {
      console.log(this.get('session'));
      this._super();
    }
  }
});

Also a stack trace for the error would be helpful. Best would of course be a jsbin showing the error.

@bakura10
Copy link
Contributor Author

I got "undefined". Here is the code (like previous time):

The initializer:

module.export = (function() {
  Ember.Application.initializer({
    name: 'authentication',

    initialize: function(container, application) {
      Ember.SimpleAuth.setup(application, {
        routeAfterInvalidation: 'login',
        routeAfterAuthentication: 'projects'
      });
    }
  });

  Ember.SimpleAuth.Authenticators.OAuth2.reopen({
    serverTokenEndpoint: 'http://connect.saas-metrics.localhost/oauth/token'
  });
});

The application route:

module.exports = App.ApplicationRoute = Ember.Route.extend(Ember.SimpleAuth.ApplicationRouteMixin);

The login controller:

module.exports = App.LoginController = Ember.Controller.extend(Ember.SimpleAuth.LoginControllerMixin, {
  /**
   * Error message if login fails
   *
   * @type {string}
   */
  errorMessage: null,

  actions: {
    /**
     * Set an error message when authentication fails
     */
    sessionAuthenticationFailed: function(error) {
      this.set('errorMessage', JSON.parse(error).error_description);
    }
  }
});

And finally the login template:

<h2>Login Template</h2>

<form {{action authenticate on='submit'}}>
    <div class="control-group">
        <label for="identification">Login</label>
        {{view Ember.TextField id='identification' valueBinding='identification'}}
    </div>

    <div class="control-group">
        <label for="password">Password</label>
        {{view Ember.TextField id='password' type='password' valueBinding='password'}}
    </div>

    <button type="submit">Login</button>
</form>

{{#if errorMessage}}
    <p>{{ errorMessage }}</p>
{{/if}}

Sorry if I miss something again :(.

@bakura10
Copy link
Contributor Author

Btw, it would be a nice addition if Ember-Simple-Auth would extract automatically the error message, as it's standardized to be under the "error_description" key. What do you think ? :)

@marcoow
Copy link
Member

marcoow commented Jan 20, 2014

Btw, it would be a nice addition if Ember-Simple-Auth would extract automatically the error message, as it's standardized to be under the "error_description" key. What do you think ? :)

Sounds like a good idea to add that to Authenticators.OAuth2.

Regarding your problem - is Ember.SimpleAuth.setup running before your controller is created? Maybe the module transpilation somehow changes the order of things there so that the initializer runs later or so?

@bakura10
Copy link
Contributor Author

No, it seems initializers are run before controllers. I'll dig a bit more tomorrow...

@bakura10
Copy link
Contributor Author

I found it. Actually, the syntax I tried to use:

module.export = (function() {
  Ember.Application.initializer({
    name: 'authentication',

    initialize: function(container, application) {
      alert('ok');
      Ember.SimpleAuth.setup(application, {
        routeAfterInvalidation: 'login',
        routeAfterAuthentication: 'projects'
      });
    }
  });

  Ember.SimpleAuth.Authenticators.OAuth2.reopen({
    serverTokenEndpoint: 'http://connect.saas-metrics.localhost/oauth/token'
  });
});

for module exporting was wrong and the initializer was not called. Here is the correct one:

module.export = Ember.Application.initializer({
    name: 'authentication',

    initialize: function(container, application) {
      alert('ok');
      Ember.SimpleAuth.setup(application, {
        routeAfterInvalidation: 'login',
        routeAfterAuthentication: 'projects'
      });
    }
  });

  Ember.SimpleAuth.Authenticators.OAuth2.reopen({
    serverTokenEndpoint: 'http://connect.saas-metrics.localhost/oauth/token'
  });

I need to learn more about modules. I thought I needed to do that so that Ember.SimpleAuth.Authenticators get wrapped too

@marcoow
Copy link
Member

marcoow commented Jan 20, 2014

cool

@marcoow marcoow closed this as completed Jan 20, 2014
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