Detect first time login of new user using googleAuth – Firebase 9

featured Image

In this short article, we will see how we can detect the first-time login of a new user using googleAuth in firebase 9.

If you are working with google Authentication in firebase, then to detect if the user has signed-in for the first time or not, you have to use the AdditionalUserInfo that is provided by firebase.

The AdditionalUserInfo contains additional user information as a result of a successful sign-in or re-authentication operation.

Check if the user logged in for the first time using googleAuth firebase.

Let’s see the steps on how to import the getAdditionalUserInfo in our firebase project to get additional user information.

In firebase 9, we have to import the getAdditionalUserInfo module from firebase/auth.

import { getAdditionalUserInfo } from "firebase/auth";

Next, after a successful sign-in with the signInWithPopup we can use the isNewUser property provided by getAdditionalUserInfo module to check if the user has signed in for the first time or not.

import {  signInWithPopup, getAdditionalUserInfo } from "firebase/auth";

function signInWithGoogleAuth() {
    signInWithPopup(auth, provider)
        .then(async (result) => {
            const isFirstLogin = getAdditionalUserInfo(result).isNewUser
         }
}

isNewUser returns boolean as result.

So in the above code, if the user have signed in for the first time, isFirstLogin will return true, else it will return false.

This is how you can check if user is authenticated for the first time in Firebase Google Authentication.

Related Posts

git commands with example

Top 40 Git commands with Examples

GitHub has become an essential tool for developers to manage, store, and collaborate with other developers on software projects. With its simple powerful git-based version control system, GitHub allows users…

Read more
Check GitHub Account in the Terminal

Check GitHub Account in the Terminal

GitHub is an integral tool for developers to store, manage, and collaborate on software projects with other developers. And as we work more and more in the command line it…

Read more
featured Image

How to make list of objects in Netlify CMS using list and object Widget

Here in this Netlify CMS tutorial we will how easily we can make a list of objects using list and object widgets. This will allow us to add multiple objects…

Read more