# Ember-simple-auth dummy app

**URL:** <https://discuss.emberjs.com/t/ember-simple-auth-dummy-app/14193>\
**Category:** Uncategorized\
**Created:** [February 1, 2018, 9:42am UTC](https://discuss.emberjs.com/t/ember-simple-auth-dummy-app/14193 "2018-02-01T09:42:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![belgoros](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/belgoros/32/16101_2.png) [@belgoros](https://discuss.emberjs.com/u/belgoros)\
**Post date:** [February 1, 2018, 9:42am UTC](https://discuss.emberjs.com/t/ember-simple-auth-dummy-app/14193/1 "2018-02-01T09:42:50Z")

</div>

I tried to play a little bit with ember-simple-auth [dummy app](https://github.com/simplabs/ember-simple-auth/tree/master/tests/dummy) and have some questions:

1. Why even after being authenticated with Implicit Grant authorizer, the following div block in `index.hbs` is still displayed:

```auto
{{#unless session.isAuthenticated}}
  <div class="alert alert-info">
    You can {{#link-to 'login' classNames='alert-link'}}log in{{/link-to}} with login <code>letme</code> and password <code>in</code>.
  </div>
{{/unless}}

```

After the authentication is successful, the value of `{{#unless session.isAuthenticated}}` should be `false` but it is not the case.

1. The same check works fine in another template - `main-navigation.hbs`:

```auto
{{#if session.isAuthenticated}}
      <a {{action 'logout'}} class="btn btn-danger navbar-btn navbar-right">Logout</a>
      {{#if sessionAccount.account}}
        <p class="navbar-text pull-right">Signed in as {{sessionAccount.account.name}}</p>
      {{/if}}
    {{else}}
      <a {{action 'login'}} class="btn btn-success navbar-btn navbar-right">Login</a>
    {{/if}}

```

The button Login/Logout is displayed correctly depending of your athentication status.

1. What does this code from `main-navigation.hbs` mean:

```auto
{{#if sessionAccount.account}}
      <p class="navbar-text pull-right">Signed in as {{sessionAccount.account.name}}</p>
{{/if}}

```

What is `account`? Where and how is it set in the application ? Sure, there is a model `account`, but how do we fetch the data for this model and where from ?

1. In `sessions-account.js` service we are finding the account as follows:

```auto
loadCurrentUser() {
    return new RSVP.Promise((resolve, reject) => {
      const accountId = this.get('session.data.authenticated.account_id');
      if (!isEmpty(accountId)) {
        this.get('store').find('account', accountId).then((account) => {
          this.set('account', account);
          resolve();
        }, reject);
      } else {
        resolve();
      }
    });
  }

```

But where do we set the value for `session.data.authenticated.account_id`?

1. What does `onLogin` mean in `templates/application.hbs`and where it comes from:

```auto
{{main-navigation onLogin='transitionToLoginRoute'}}

```

1. Why do we prefix the method with underscore in `routes/application.js`:

```auto
beforeModel() {
    return this._loadCurrentUser();
  },

  sessionAuthenticated() {
    this._super(...arguments);
    this._loadCurrentUser();
  },

  _loadCurrentUser() {
    return this.get('sessionAccount').loadCurrentUser().catch(() => this.get('session').invalidate());
  }

```

Thank you!

---

<div class="post-metadata">

**Author:** ![broerse](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/broerse/32/9497_2.png) [@broerse](https://discuss.emberjs.com/u/broerse)\
**Post date:** [February 1, 2018, 6:18pm UTC](https://discuss.emberjs.com/t/ember-simple-auth-dummy-app/14193/2 "2018-02-01T18:18:57Z")

</div>

I don’t know if it helps but I have an other working Example here [https://github.com/broerse/ember-cli-blog/](https://github.com/broerse/ember-cli-blog/) you can test here: [Myapp](https://bloggr.exmer.com/secret)

---

<div class="post-metadata">

**Author:** ![belgoros](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/belgoros/32/16101_2.png) [@belgoros](https://discuss.emberjs.com/u/belgoros)\
**Post date:** [February 1, 2018, 8:47pm UTC](https://discuss.emberjs.com/t/ember-simple-auth-dummy-app/14193/3 "2018-02-01T20:47:09Z")

</div>

@broerse, Thank you very much. The problem I actually have - is that all the examples I could find in books and on the Web use either a **standard** provider or a **username/password** authentication, - all of them are enough clear for me and I could get all of them work. In [my app](https://github.com/belgoros/decastore-ember) I’ll have to use `OAuth2ImplicitGrant` authenticator. And ESA `dummy` app where I pull most of the code from, has an issue with session authentication (I tried to run it locally as described in my earlier post). If somebody could be explain what is wrong with that, it would be really appreciated :). Thank you !
