# User authentications and application controller

**URL:** https://discuss.emberjs.com/t/user-authentications-and-application-controller/9194
**Category:** Uncategorized
**Created:** [November 26, 2015, 2:13pm UTC](https://discuss.emberjs.com/t/user-authentications-and-application-controller/9194 "2015-11-26T14:13:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![carlitoxti](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@carlitoxti](https://discuss.emberjs.com/u/carlitoxti)
#### Post date: [November 26, 2015, 2:13pm UTC](https://discuss.emberjs.com/t/user-authentications-and-application-controller/9194/1 "2015-11-26T14:13:14Z")

</div>

Hello, i need to call a method who is define in my application controller since a route, post/comment/new route because i like to deny access this route for users are not authenticated.

```
import Ember from 'ember';
import App from '../app';

export default Ember.Controller.extend({
  authManager: App.AuthManager,

  currentUser: function() {
    return App.AuthManager.get('apiKey.user');
  }.property('authManager.apiKey'),

  isAuthenticated: function() {
    return App.AuthManager.isAuthenticated();
  }.property('authManager.apiKey'),
});

```

in my applycation.hbs, i have: {{#if isAuthenticated}} and it respond NO, BUT if a call this method in my post/comment/new.hbs it respon yes, i think it because in the if this method is not declared, so how i do that? thanks

---

<div class="post-metadata">

### Author: ![workmanw](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/workmanw/32/14929_2.png) [@workmanw](https://discuss.emberjs.com/u/workmanw)
#### Post date: [November 27, 2015, 3:54pm UTC](https://discuss.emberjs.com/t/user-authentications-and-application-controller/9194/2 "2015-11-27T15:54:47Z")

</div>

I assume the code you provided is your application controller? And the `App.AuthManager` is some other object/controller you’re using to store the global state for the user. If I am wrong about either of those two assumptions, please let me know.

I think the first thing you should do is make your `App.AuthManager` a service. It sounds like functionally it’s probably already close to that. Here is a good reference on doing that: [Services - Application Concerns - Ember Guides](http://guides.emberjs.com/v2.2.0/applications/services/)

Once you’ve done that, your application controller should look something like this:

```
import Ember from 'ember';

export default Ember.Controller.extend({
  authManager: Ember.inject.service(),

  currentUser: Ember.computed.reads('authManager.apiKey.user'),
  isAuthenticated: Ember.computed.reads('authManager.isAuthenticated')
});

```

* * *

Edit: I wanted to point out that you can also use `authManager: Ember.inject.service()` on Components and Routes to access it.
