Allow only one session per user in perspective

Hi,

I am trying to implement one session per user at a time in perspective and using following code.

It does work, however the 2nd screen where user tried to log in, some how is logging out as soon as you click on Continue to log-in. (like its remembering previous user info).

what is the best way?

Here is the script.
</>

> # Limit users to one session at a time.
> 	current_project = system.perspective.getProjectInfo().name
> 	for session_obj in system.perspective.getSessionInfo(usernameFilter=session.props.auth.user.userName, project=current_project):
> 		if (session_obj["sessionScope"] != "designer") and session_obj["id"] != session.props.id:			
> 			system.perspective.closeSession(message="You are limited to one session at a time.")

</>

Also close session only gives an option to launch gateway. I dont want that to be exposed. Whats the best way.?

Thanks

Try navigating to a second, unsecured project via URL.

But what is the correct script to not allow them to log into multiple screens? Keep in mind i have multiple projects. So a startup gateway script also doesnt work well

I would bind the user id in the session to a custom property, with a change script to catch logon. That change script would loop through all sessions for the project, looking for that matching user name. Any found would be used to trigger navigation in every page to a dummy project (specifying sessionId and pageId in the navigate() function), then closing the session with system.perspective.closeSession() to catch any stragglers.

Note that you cannot prevent a new user occupying a new session. It is only practical to boot out any prior sessions.

If a user tries to navigate back to the project they were booted from, they'll have to re-authenticate, which will trigger the same code to boot the other session again.

Instead of closeSession, can we perform logout? I tried but logout didnt work.

I wouldn't have expected logout to work, because I'm pretty sure you have to close the session. Ideally, each open browser tab in the session will have navigated to the dummy project, leaving no visible sign of the session closure. (Perhaps the close session should be after a brief delay.)

You'll have to experiment. You may not be able to completely hide the gateway link.

@PGriffith - any thoughts?