This post covers the solution of a frustrating question – “How to detect login window close event while using LinkedIn Javascript SDK?”
As per the documentation, we are supposed to use the following code to authenticate a user using the api:
IN.User.authorize();
The above code was also responsible for opening the login popup.
Now, in order to detect the login window’s close event, the above code needs to be replaced with the following code:
var linkedin = IN.UI.Authorize().place();
linkedin.onWindowRemove.subscribe(function() {
// perform some action
});
The linkedin
object gives us access to the LinkedIn’s authorization UI – which is usually the popup which opens when a user tries to sign in using LinkedIn.
onWindowRemove triggered in case of login success
This answers exactly the question I was looking for. But once I replace `IN.User.authorize()` with `IN.UI.Authorize().place()`, how do I respond to the normal case where the user successfully logs in?
Is this `IN.UI.Authorize().place` documented anywhere? I can’t find anything about `IN.UI` anywhere other than this page.
Thanks.
IN.UI.Authorize().place
isn’t documented anywhere. I just explored the js file and found the use of this snippet to trigger login process. When the user successfully logs in you may useIN.User.isAuthorized()
to check if the user is authorized or not and redirect the user to the corresponding page or alert the user. Give me some time and will reply back with the code I am using in my application.