I use Worklight 6.1 and use a call handler to determine if my user is registered or not.
After logging in, I have the following code attached to my logout button in my application:
on(logoutBtn, "click", lang.hitch(this, function() {
WL.Client.logout('AdapterAuthRealm', { onSuccess:lang.hitch(this, function() {
this.gotoView("login");
}), onFailure:lang.hitch(this, function() {
WL.Logger.error("Unable to logout");
})});
return false;
}));
Clicking on it opens the login window, but when the user tries to log in again, the following error is displayed:
"Cannot change identity of an already logged in user in realm 'AdapterAuthRealm'.
The application must logout first."`
According to the following SO question:
Backlight: WL.Server.setActiveUser - Unable to change - Invalid state: unable to change identifier
First I have to clear the active user before installing a new one:
WL.Server.setActiveUser("AdapterAuthRealm", null);
, WL.Client.logout , onLogout , , :
<realm loginModule="NonValidatingLoginModule" name="AdapterAuthRealm">
<className>com.worklight.integration.auth.AdapterAuthenticator</className>
<parameter name="login-function" value="PortalAdapter.onAuthRequired"/>
<parameter name="logout-function" value="PortalAdapter.onLogout"/>
</realm>
function onLogout() {
WL.Logger.info("invoke logout request");
WL.Server.setActiveUser("AdapterAuthRealm", null);
var input = {
method : 'get',
returnedContentType : 'text/plain',
path : '/logoutUrl'
};
WL.Server.invokeHttp(input);
}
:
var userIdentity = { userId: username, displayName: username, attributes: {}};
WL.Server.setActiveUser("AdapterAuthRealm", null);
WL.Server.setActiveUser("AdapterAuthRealm", userIdentity);
/ .
:
- / ?
- Challange WL.Client.logout?