Single login only at once

trying to do –
hellow i have created a application and i want to ensure that that my app is login at one place at a time

do this —
suppose person A uses example@email.com to logon
so if B also have credential access If login with same account
user A must get logout ?
is their anything i can do

Welcome to the forum!

Enforcing a single login at a time isn’t something you can do by changing a setting. You would need to code it into your app. The only approach I can think of is to generate a random id (e.g. a UUID4) when a user logs in, and store it in both the Users table and the server side session.

At some point in the login process (after the user logs in, but before you generate the number) you can check to make sure the session and User table values match. If they don’t, you can do whatever you want. In your case generate a new random value.

In every server side function that is used by logged in users, you can check the two values to see if they match. If they don’t, return an error that the client code can use to log the user out.

Hopefully someone else will come up with a simpler approach.

Similar to what @jshaffstall says, something like this may work:

  • When a user signs in, it calls a server function called new_sign_in
  • The new_sign_in function gets the session id with anvil.server.get_session_id() and stores it in the Users table
  • Every time the app does a server call, every server callable checks if the anvil.server.get_session_id() matches the session id stored in the Users table, and…
    – if it doesn’t, it will return an error to let the form know that it needs to sign out
    – if it does, it will do its job and return whatever it needs to return
  • Optionally, a timer in the form calls the server function called check_other_sign_in every 5 seconds, and if the function returns True, the app shows a notification and signs out
1 Like

Maybe this can be of some help?

1 Like