mercredi 23 octobre 2019

User loading after authentication with ember simple auth

I use ember simple auth to authenticate my users. It workls perfectly fine except when the user just logged in.

I have an helper that ask for the current user :

import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';

export default Helper.extend({
  currentUser: service('current-user'),
  compute([feature,currentUser]) {
    let role = currentUser.get('user.role')

Helper is used in a template embedded in a template in application.hbs


  <li><i class="fa fa-user"></i> <span>Clients</span></li>
  

The current user service is a duplicate of this one from the doc : https://github.com/simplabs/ember-simple-auth/blob/master/guides/managing-current-user.md#loading-the-user-with-its-id

And my application.js is also using the code from the same guide.

From what I tried, the sessionAuthenticated start to run, and during await this._loadCurrentUser(); the helper is executed, and it finish to run sessionAuthenticated

What happen is that the user attribute I want is undefined and it make it impossible to display interface elements according to the role of the User.

How can I fix this problem?

Edit for related question :How does ember simple auth is supposed to be used in template to determine if User is supposed to see some part of the interface or not ? Like for example menu choices.




Aucun commentaire:

Enregistrer un commentaire