Anvil.users.get_user() and security

Hi @hans.melberg,

As @david.wylie and @stucork have suggested, it’s good practice to perform validation checks on both the client-side and server-side. I normally use an alert to display validation errors on the client-side, and raise an Exception server-side in response to validation errors. You might find this how-to guide in the docs helpful.

If you’re using the Users Service, you can also customise your @anvil.server.callable decorators inside your Server Modules to check that a user is logged in:

authenticated_callable = anvil.server.callable(require_user=True)

# This will raise an anvil.users.AuthenticationFailed Exception 
# if there is no logged-in user.
@authenticated_callable
def get_data():
  return data
9 Likes