Question

I am not able to get Worklight logout working.

The logout button:

<input type="button" value="Logout2" onclick="WL.Client.logout('AuthRealm',{onSuccess: WL.Client.reloadApp})" />

When click to it I get:

onLogoutSuccess: realm: AuthRealm is undefined

But the realm is defined well and logout function of this realm is called after click. I investigated Worklight sources and found out that the problem is in:

onLogoutSuccess(transport=klass { request=klass, transport=XMLHttpRequest, readyState=4, more...})wlclient.js (line 1298)

So the error is thrown from:

if (typeof userInfo[realm] === "undefined") {
    WL.Logger.error('onLogoutSuccess: realm: ' + realm + ' is undefined');
    return;
} 

Where should I set up userInfo? Or why is this error thrown? I didn't find any info in example sources.

Was it helpful?

Solution

I was able to reproduce only when my device had not yet connected to the Worklight server in any way (has not yet logged into the realm, initOnStartup=false, no adapter calls, etc)

It appears that if the client has not yet communicated with the Worklight server, it knows nothing about the realm and so it throws an error when trying to log out of the realm. Try either adding a check to see if the user has logged into the realm or making sure that the user has connected to the Worklight server before they are able to log out.

Even if they haven't yet logged into the realm, the device will know about the realm if it has connected to the server at least once.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top