Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4828

Ember-simple-auth dummy app

$
0
0

@belgoros wrote:

I tried to play a little bit with ember-simple-auth dummy app and have some questions:

  1. Why even after being authenticated with Implicit Grant authorizer, the following div block in index.hbs is still displayed:
{{#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:
{{#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:
{{#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:
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.hbsand where it comes from:
{{main-navigation onLogin='transitionToLoginRoute'}}
  1. Why do we prefix the method with underscore in routes/application.js:
beforeModel() {
    return this._loadCurrentUser();
  },

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

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

Thank you!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles