PatrickJS / angular-intercom

An Angular.js wrapper for Intercom.io providing a simple and familiar API for Angular Developer.
MIT License
89 stars 36 forks source link

How to know was boot method call or not? #26

Closed daruwanov closed 8 years ago

daruwanov commented 9 years ago

Hello. I have a question. This is not a bug just a question. I call boot method when user is log in in to my app. But if user reload the page, or close the page and open it again - and still have valid access token inside my app. he don't enter his login password etc.. So is this any possibility to know was boot method called or not? I mean i on every state change event - i want check is boot was called - everything is good. intercom is alive :) if not call boot method? Or it`s normal call boot every time?

yjwong commented 9 years ago

I'm not too sure how your authentication system is implemented. Do you fetch user information with the access token every time the page is reload? If yes, then you can call the boot method on every page reload, if the fetch for user information succeeds.

It could be something like this that is placed in the Angular run() block, so this code gets called on every page reload:

$http
  .get('/api/me', {
    headers: { 'Authorization': 'Bearer <token>' }
  })
  .then(function (user) {
    // User is logged in.
    $intercom.boot(user);
  })
  .catch(function (err) {
    // User is not logged in.
  });
daruwanov commented 8 years ago

@yjwong

Do you fetch user information with the access token every time the page is reload? If yes, then you can call the boot method on every page reload, if the fetch for user information succeeds.

Yes.. When route is change a check is current access token is valid etc... Angular not actually make full page reload... As i understand that mean that if we call boot method once, after state change and user auth data is valid, we will call boot again.. i am right? is that good to call it twice?

niemyjski commented 8 years ago

I don't think it hurts anything. I know I was calling update in a set interval in my app instead https://github.com/exceptionless/Exceptionless.UI/blob/master/src/components/intercom/intercom-directive.js#L140-L151

daruwanov commented 8 years ago

@niemyjski Great! Thanks. I don't get any problem with it now. So the question is resolve for me.