Identity Providers
We allow users to authenticate with an external provider account, such as a Google account or an Apple account.
select one or several providers
Note: We enable providers in the Firebase console.
const gProvider = new GoogleAuthProvider() // Google Provider
authentication flows
Possible flows:
- the user authenticates through a popup window.
- the user authenticates through a redirect.
Flows handle both sign-in and sign-up: we describe a flow with a generic control label:
- "Authenticate with Foo"
- "Continue with Foo"
Both flows trigger an authentication event on success. They return a credential (UserCredential), that embeds the user object:
const credential = await signInWithPopup(auth, gProvider)
credential.user // User
Note: We can detect it is a new user through a helper method:
const userInfo = getAdditionalUserInfo(credential)
if (userInfo?.isNewUser) {
}
popup flow
The popup flow may fail if the browser doesn't allow popups.
const credential = await signInWithPopup(auth, gProvider)
redirect flow
The redirect flow relies on navigating to another page and navigating back.
It requires extra work unless the website is hosted on Firebase Hosting.