Worklight - How to check if a client is already lo

2019-02-20 10:02发布

I get the following error when I log in the second time in my login screen.

    [ERROR   ] FWLSE0099E: An error occurred while invoking procedure  [project Klappr]KlapprAuthAdapter/submitAuthenticationFWLSE0100E:  parameters: [project Klappr]{
       "arr": [
  "dGVzdDp0ZXN0"
   ]
  }
   Cannot change identity of an already logged in user in realm 'KlapprAuthRealm'. The application must logout first.
    FWLSE0101E: Caused by:  [project Klappr]null 
                                                                                                           com.worklight.common.log.filters.ErrorFilter

In submitauthentication (in the adapter) I check if the username and password are correct and if they are correct I set the activeUser in the WorklightRealm like this:

    WL.Server.setActiveUser("KlapprAuthRealm",{
                        userId:""+teacher.id,
                        displayName: teacher.voornaam,
                        credentials:loginstring,
                        attributes: {
                            "teacherId": teacher.id,
                        }
                    });

How can I check if the user is already logged in? Is this best on client side before I show the loginpage? Or should I let them be able to log in another time, and if they are already logged in, also return the userId?

2条回答
家丑人穷心不美
2楼-- · 2019-02-20 10:46

This is happening because you're trying to set active user but it is already set. A possible solution might be to call WL.Server.setActiveUser("KlapprAuthRealm", null) before setting active user with actual user identity.

查看更多
别忘想泡老子
3楼-- · 2019-02-20 11:00

If you want to check on the client side for before submission:

WL.Client.isUserAuthenticated("KlapprAuthRealm")

May want to read the docs on the WL.Client.createChallengeHandler to handle the session and login flow

查看更多
登录 后发表回答