@belgoros wrote:
I tried to play a little bit with ember-simple-auth dummy app and have some questions:
- 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 befalse
but it is not the case.
- 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.
- 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 modelaccount
, but how do we fetch the data for this model and where from ?
- 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
?
- What does
onLogin
mean intemplates/application.hbs
and where it comes from:{{main-navigation onLogin='transitionToLoginRoute'}}
- 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