securityember.jsuser-profileember-simple-auth

EmberJS: global class functions depend on a session variable, using Ember-Simple-Auth. Best Practice?


I had a question regarding best practice when it comes to building a global utility class in EmberJS when the class will exhibit user-specific behavior.

The following conditions are all true:

  1. The class's methods could be accessed from anywhere in the entire application.
  2. The application performs JSON based authentication using Ember-Simple-Auth.
  3. The authentication confirmation payload comes with some information about the user.
  4. The information received in the token payload will determine the behavior of the utility class's function.

My Questions

  1. Is a Util the best option? Should I be using services and somehow "initialize" this service on a confirmed authentication? My end goal is to use this class from almost every route/template/component in my application.

  2. How chill are authentication payloads? Is it OK to send crumbs of user specific information information in the authentication payload in addition to any tokens?


Solution

  • The best choice is using services.

    They are :

    Is a Util the best option?

    No. Services is best option. You can initialize it after successful authentication hook of ESA. And it could be injected everywhere

    How chill are authentication payloads?

    You can send anything. Your authenticator is responsible to process it. The payload is saved in data.authenticated object in ESA session service