This system ensures that their data is protected and that only authorized individuals can pull up the software.

Using NextAuth, you’re free to shift your focus to building the core features.

Read on to learn how to integrate Google social login in your system using NextAuth.

A laptop sitting on a counter in front of a window. The laptop has some JavaScript code on the screen.

Under the hood, when a user attempts to access, they are redirected to Google’s sign-in page.

This data is used to authorize access to the software and its resources.

The session token is used to verify the user’s identity and persist their authentication status.

a login page is displayed on a samsung device

This process also applies to other providers with slight variations in the implementation.

Register Your Next.js tool on Google Developer Console

NextAuth provides support for Google authentication service.

Once logged in, create a new project.

Create Project on Google Developer Console

punch theCreate Credentialsbutton to generate your Client ID and Client Secret.

Afterward, specify your app’s home route URL and finally specify the authorized redirect URI for your system.

For this case, it should behttp://localhost:3000/api/auth/callback/googleas specified by NextAuth’s Google provider configs.

Google Developer Console settings

Open your net surf tool and navigate to http://localhost:3000.

This should be the expected result.

you might find this project’s code in itsGitHub repository.

Setting up a google client id and secret by clicking the create credentials button

Integrate NextAuth in Your Next.js system

First, install NextAuth’s library into your project.

Next, in the/pagesdirectory, create a new folder and name itapi.

This code configures Google as the authentication provider.

OAuth Client Settings

Next, open thepages/_app.jsfile and make the following changes to the code.

NextAuth’sSessionProvidercomponent provides authentication state management functionality to the Next.js app.

This code uses Next.jsuseRouterhook to handle routing within the app by defining a router object.

nextjs dev server start screen

You canconnect a PostgreSQL database with your Next.js app using Prisma.

The signOut hook allows a user to sign out of the tool.

This hook will delete the session object created during the sign-in process and the user will be signed out.

Further, you canuse Tailwind CSS with your Next.js appto style the authentication models.