Live Chat

We'll need to share your messages (and your email address if you're logged in) with our live chat provider, Drift. Here's their privacy policy.

If you don't want to do this, you can email us instead at contact@anvil.works.

Authenticating Users with Google

Your users can log in to their Google accounts in your app. It’s easy to add Google login to the Users Service - see Users:Authentication Choices to see how.

If you want to use the Anvil Google API to present a login form just for Google accounts, this section tells you how. You may wish to do it this way if you don’t want to store your users email addresses in your app’s Users table.

You don’t need the user to log in to Google if you only use app files or send email. Those belong to the app, not the user.

Log in

To allow your users to log into your app with Google, call anvil.google.auth.login().

import anvil.google.auth

email_addr = anvil.google.auth.login()
print("User logged in as %s" % email_addr)

If the login succeeds, anvil.google.auth.login() will return the user’s email address.

If the login fails, or the user cancels, anvil.google.auth.login() will raise an exception.

Check who is logged in

To find out who is currently logged in, call anvil.google.auth.get_user_email(). If nobody is logged in, this returns None.

import anvil.google.auth

# This can run on the server:
email_addr = anvil.google.auth.get_user_email()
print("%s is now logged in" % email_addr)

The get_user_email function can be called from a Server Module, or Uplink code, to check whether a user is authorised to perform the requested action.