auth0 / angular-lock

MIT License
18 stars 15 forks source link

Having trouble listening to authenticated event #6

Closed rajibahmed closed 8 years ago

rajibahmed commented 8 years ago

Hi,

I was following the example codes from all the samples and readme file. I tried copy and pasting the example code it never firing the "authenticated" event.

failing code --- on run block

   lock.on('authenticated', function(result){
      debugger;
    });

    authManager.checkAuthOnRefresh();
    authManager.redirectWhenUnauthenticated();

working code ---- on run block

   lock.interceptHash();

   lock.on('authenticated', function(result){
      debugger;
    });

    authManager.checkAuthOnRefresh();
    authManager.redirectWhenUnauthenticated();

This method - interceptHash is not documented and I had to read through the libs to figure this out. Bit annoying. Other repo has this example 02-Custom-Login using has this line ....

var result = angularAuth0.parseHash(window.location.hash);

auth0 provides the JWT on callback url ... without parsing that ..... HOW all the example code is going to function ???

chenkie commented 8 years ago

Thanks, I've updated the readme to reflect lock.interceptHash()

Can you describe the other issue a bit more?

rajibahmed commented 8 years ago

the thing is, as I have read through the documentation of lock,

lock.intercept()

method are suppose to be called automatically, when auth0 callback provides the token through url, while redirecting.

Funny thing is, it was not calling this method or intercepting based on the url. As, the authenticated event is triggered inside of this method. As idToken is not retrieved , stored and authenticated event is never trigger.

And the second things was, I knew about this method from auth0 library code. I was looking for it on the examples from this repo so I can interface to this method. the Api library (angularAuth0) documents this method on README and this repo don't .... even though its a public (proxy) method auth0 lib function call.

This caused me ton of headache and annoyance.

wootencl commented 8 years ago

Want to mention that using lock.interceptHash() in nonui-router NG apps will cause the authenticated event to fire twice which is a bit annoying.

chenkie commented 8 years ago

Thanks @wootencl, we'll see about putting in a check for that.