# Allow only one session per user in perspective

**URL:** <https://forum.inductiveautomation.com/t/allow-only-one-session-per-user-in-perspective/86476>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 28, 2024, 12:08am UTC](https://forum.inductiveautomation.com/t/allow-only-one-session-per-user-in-perspective/86476 "2024-02-28T00:08:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eagel007](https://avatars.discourse-cdn.com/v4/letter/e/7bcc69/32.png) [@Eagel007](https://forum.inductiveautomation.com/u/Eagel007)\
**Post date:** [February 28, 2024, 12:08am UTC](https://forum.inductiveautomation.com/t/allow-only-one-session-per-user-in-perspective/86476/1 "2024-02-28T00:08:12Z")

</div>

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.  
\</\>

```auto
> # 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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 28, 2024, 12:14am UTC](https://forum.inductiveautomation.com/t/allow-only-one-session-per-user-in-perspective/86476/2 "2024-02-28T00:14:14Z")

</div>

Try navigating to a second, unsecured project via URL.

---

<div class="post-metadata">

**Author:** ![Eagel007](https://avatars.discourse-cdn.com/v4/letter/e/7bcc69/32.png) [@Eagel007](https://forum.inductiveautomation.com/u/Eagel007)\
**Post date:** [February 28, 2024, 12:19am UTC](https://forum.inductiveautomation.com/t/allow-only-one-session-per-user-in-perspective/86476/3 "2024-02-28T00:19:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 28, 2024, 12:28am UTC](https://forum.inductiveautomation.com/t/allow-only-one-session-per-user-in-perspective/86476/4 "2024-02-28T00:28:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Eagel007](https://avatars.discourse-cdn.com/v4/letter/e/7bcc69/32.png) [@Eagel007](https://forum.inductiveautomation.com/u/Eagel007)\
**Post date:** [February 28, 2024, 6:29pm UTC](https://forum.inductiveautomation.com/t/allow-only-one-session-per-user-in-perspective/86476/6 "2024-02-28T18:29:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 28, 2024, 6:34pm UTC](https://forum.inductiveautomation.com/t/allow-only-one-session-per-user-in-perspective/86476/7 "2024-02-28T18:34:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Eagel007](https://avatars.discourse-cdn.com/v4/letter/e/7bcc69/32.png) [@Eagel007](https://forum.inductiveautomation.com/u/Eagel007)\
**Post date:** [February 28, 2024, 6:38pm UTC](https://forum.inductiveautomation.com/t/allow-only-one-session-per-user-in-perspective/86476/8 "2024-02-28T18:38:43Z")

</div>

@paul-griffith - any thoughts?
