Firebase: Sign in with Google

Here is a quick guide to use the “Sign in with google” functionality using the anvil-firebase library.

  1. Go to firebase console and add authentication to your project.

In the Authentication View

  1. Under Sign-in method, enable Email/Password and Google as your provider. (Email/Password is required to view/add users)
  2. Go to the Settings Tab and add your custom log-in domain to authorized domains.

In your Log in Form

  1. Add a button with a click event
  2. Set your click event to the following:
  def button_google_auth_click(self, **event_args):
    """This method is called when the button is clicked"""
    provider = authentication.proxy_auth.GoogleAuthProvider()
    authentication.auth.languageCode = 'en' #choose your language
    result = authentication.proxy_auth.signInWithPopup(authentication.auth,provider)

Badabing-Badaboom! you have now been authenticated via your google auth using your firebase client.

Here are the firebase docs

Thanks community!

6 Likes

For some reason I cannot find this question on the forum!

Either way,

By default sign ins are locally persistent. You only have to check, in your startup form, for an authorized user.

See here : https://firebase.google.com/docs/auth/web/auth-state-persistence#web

You can check with the authentication library:

user = authentication.get_user()

Hope that helps!

1 Like

Thank you! Sorry, I basically figured that out and then deleted my comment. But I should have realized you’d probably already received my question by email. Next time I’ll update rather than delete!

1 Like