SpoonX / aurelia-authentication

Authentication plugin for aurelia.
http://aurelia-authentication.spoonx.org
MIT License
90 stars 60 forks source link

Authentication-Change Not Firing in app.ts #376

Closed gregoryagu closed 6 years ago

gregoryagu commented 6 years ago

I need to be able to process the authentication-change in app.ts.

So I have this code in app.ts:

this.eventAggregator.subscribe('authentication-change', authenticated => {
      alert(authenticated);
  });

This works fine if the user logs in through the use of the login form.

However, after he is logged in, and their is a token in local-storage, then the event does not fire in app.ts. the next time they log in. In other words, the token is found in local-storage, there is no need for the user to log in again, and aurelia-auth automatically sets authenticated to true. I do see the message in the console that Authentication was set to true. So the event is firing. But it seems that the event is not yet wired up in app.ts, so my code is not triggered when the auto-login occurs.

Is there some way to wire it up in main.ts so that it will fire when the user automatically logs in?

gregoryagu commented 6 years ago

I realized after I wrote this that all I need to do is check for authentication=true in the constructor of the App, and if so, then configure the app appropriately. If not, then later when authentication-change does fire, I can configuration appropriately then.

So I am going to close this ticket.