Session logout/restart through server side script

tj2
Kilo Contributor

Hi,

Is there any way by which we can logout or restart user session in a server-side script ?

3 REPLIES 3

john_andersen
Tera Guru

I have never had a business case to do this, but I think you can do it to a current user session by using the setLoggedIn() function.

Here is an example:



//log out of current session
gs.getSession().setLoggedIn(false);


Linda Kendrick
Kilo Guru

Did you find a solution that worked?


abeyahmad
Kilo Explorer

The example John provided does not work on Geneva or Helsinki. But I found a solution!



gs.getSession().loggedIn = false;



Edit: The above solution worked too well. I had to restart my browser to be able to log back in. I found a different solution:



var gr = new GlideRecord('v_user_session');
gr.get('session_id',gs.getSession().sessionID);
gr.locked = true;
gr.update();



Warning: I got the follow error message: getEventTarget() called with invalid record reference: v_user_session.b3a6663f6f37d200234f5bc44b3ee414 for event: user.view, could have been deleted