Worklight - How to check if a client is already logged in, then pass the login screen

前提是你 提交于 2019-12-30 12:59:19

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/20118478/worklight-how-to-check-if-a-client-is-already-logged-in-then-pass-the-login-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!