<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abigail Amadi</title>
    <description>The latest articles on DEV Community by Abigail Amadi (@abbynoz).</description>
    <link>https://dev.to/abbynoz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1451395%2F602fca36-f3aa-4164-abe3-f1fb5cdd78d8.png</url>
      <title>DEV Community: Abigail Amadi</title>
      <link>https://dev.to/abbynoz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abbynoz"/>
    <language>en</language>
    <item>
      <title>Steps to Adding Google Login to Your React App</title>
      <dc:creator>Abigail Amadi</dc:creator>
      <pubDate>Fri, 26 Apr 2024 14:46:45 +0000</pubDate>
      <link>https://dev.to/abbynoz/steps-to-adding-google-login-to-your-react-app-3m2j</link>
      <guid>https://dev.to/abbynoz/steps-to-adding-google-login-to-your-react-app-3m2j</guid>
      <description>&lt;p&gt;In today's digital landscape, web applications prioritize user access security and responsible data management. Often, users seek swift access to a program without creating and managing a new account. Meanwhile, app proprietors compel user registration for the purpose of monitoring and obtaining feedback. To access these statistics, users must sign up with their email addresses. Integrating user authentication services such as Google Login has become an increasingly common and convenient way to achieve this balance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before proceeding with this tutorial, you should have a solid understanding of React and basic knowledge of npm, Node.js, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create A React Project
&lt;/h3&gt;

&lt;p&gt;Begin by creating a React project using the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app google-react-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Installing Dependencies
&lt;/h3&gt;

&lt;p&gt;To utilize the Google login package, first install it. To install the package, run the command below:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install @react-oauth/google@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After installation, our application will be wrapped with the &lt;code&gt;&amp;lt;GoogleOAuthProvider&amp;gt;&lt;/code&gt; and we will provide our google web client ID at a later stage. This will enable our entire React application to access the GoogleAuth provider at one time.&lt;/p&gt;

&lt;p&gt;Inside our &lt;code&gt;index.js&lt;/code&gt; file, we'll wrap the application as follows:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import { GoogleOAuthProvider } from '@react-oauth/google';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  &amp;lt;GoogleOAuthProvider clientId='//Google Client ID'&amp;gt;
  &amp;lt;React.StrictMode&amp;gt;
    &amp;lt;App /&amp;gt;
  &amp;lt;/React.StrictMode&amp;gt;
  &amp;lt;/GoogleOAuthProvider&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The module, like every other installed package in React, must be imported before it can be utilized. So, head to the &lt;code&gt;App.js&lt;/code&gt; file in your React app, and paste the code below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { GoogleLogin } from '@react-oauth/google';
import './App.css';
function App() {
  const responseMessage = (response) =&amp;gt; {
    console.log(response);
};
const errorMessage = (error) =&amp;gt; {
    console.log(error);
};
  return (
    &amp;lt;div className='App' &amp;gt;
      &amp;lt;h2&amp;gt;React Google Sign-In&amp;lt;/h2&amp;gt;
            &amp;lt;GoogleLogin
            className="sign"
  onSuccess={credentialResponse =&amp;gt; {
    console.log(credentialResponse);
  }}
  onError={() =&amp;gt; {
    console.log('Login Failed');
  }}
/&amp;gt;    &amp;lt;/div&amp;gt;
  );
}
export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;From the code provided above, we imported the &lt;code&gt;GoogleLogin&lt;/code&gt; module from &lt;code&gt;@react-oauth/google&lt;/code&gt; and used it in our component. Next, we define functions to handle both response and error messages from the sign-in process and render a Google Sign-In button. The button triggers these functions and logs the responses or errors to the console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709655373597_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709655373597_image.png" alt="User-uploaded image: image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our App seems ready but we cannot initate a sign-in with google OAuth without create a google client id for our App, and that’s what we’ll be doing next.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Google Sign-In
&lt;/h2&gt;

&lt;p&gt;To use Google Sign-In, we need to install the @react-oauth/google package, Google's new Identity Services SDK, which enables us to add Google login functionality to our React project. To make our Google Sign-In page fully functional, we first need to set up our project on Google Cloud and obtain our credentials.&lt;/p&gt;

&lt;h3&gt;
  
  
  Obtaining a Google OAuth Client ID
&lt;/h3&gt;

&lt;p&gt;What is a Client ID?&lt;br&gt;
A Google Client ID (or ClientID) is a unique identifier that is assigned to an application/user. It is used to authenticate clients and servers using OAuth (Auth 2.0).&lt;/p&gt;

&lt;p&gt;To get a Google Client ID, open the Google Cloud Console, and start a new project. For this tutorial, we'll name the project "GoogleReact Sign-In," but you can choose any name you prefer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709648957963_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709648957963_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating the project, navigate to the Credentials section in the API and Services menu. Here, you will find a dashboard where your current project name should be visible in the top-left corner, close to the Google Cloud logo.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709649226512_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709649226512_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, before you create your credentials, let's go over to the OAuth consent screen to set up the consent screen.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set up a Google Sign-In Consent Screen.
&lt;/h3&gt;

&lt;p&gt;The consent screen, as the name implies, is a page that requires the user to log in via an external or third party library. This popup informs the user that they are leaving your app's root page and granting access to a third-party page. example of a Google Sign-In consent screen shown below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709650221058_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709650221058_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Simply put, when you utilize OAuth 2.0 for authorization, your app asks the user to authorize one or more scopes of access using their Google account. Scopes of access include any information or activities that your app is authorized to access or do on the user's account.&lt;/p&gt;

&lt;p&gt;To set up the Google consent page for your React app, navigate to the "OAuth consent screen" tab on the left-hand menu of your Google Cloud Console.&lt;/p&gt;

&lt;p&gt;Once in this tab, select “external” the only option allowed unless you are using a Google-verified company or application, then click the “Create” button to generate your consent screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709651822313_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709651822313_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, under the same page, Provide a name for your application and an email address to receive updates on the status of the project.&lt;/p&gt;

&lt;p&gt;You can leave the remaining needs and options blank for now, but if you have the details available, you can add them during this phase.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709651956381_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709651956381_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the time being, you can skip the remaining registration sections. Simply scroll down in each section, click Save, and then return to the dashboard once completed.&lt;/p&gt;

&lt;p&gt;After designing the OAuth consent page, we must publish the app before we experiment with it or ensuring that authentication works. By default, its state is “Testing,"  and after publishing, it is moved to production.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709652366817_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709652366817_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you've marked your app as "In production," it will be accessible to everyone with a Google account.&lt;/p&gt;

&lt;h3&gt;
  
  
  Generate your web client ID.
&lt;/h3&gt;

&lt;p&gt;Now, we’ll go back to the Credential’s option to access the page where you can create your web client ID.&lt;br&gt;
On the screen, select CREATE CREDENTIALS at the top of the page, and then click the OAuth client ID.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709652754583_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709652754583_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will be asked to choose an application type as we have below. Go for Web application If you are following these steps for React (we are using the Google client ID for web).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709652952277_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709652952277_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we'll pick a name for our client ID to identify or specify the specific ID link to a single app, this name is used. To distinguish between web, iOS, and Android IDs, we can put "Web ID," "Android ID," "iOS ID," and so on in their naming conventions:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709653057778_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709653057778_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following that, we'll introduce two types of URLs: authorized JavaScript origins and authorized redirect URLs.&lt;/p&gt;

&lt;p&gt;The “Authorized JavaScript origins URL” is the URL that your application logs in from. For React developers, it’s localhost (localhost:3000) or your hosted URL if you’ve hosted your app.&lt;/p&gt;

&lt;p&gt;The “Authorized redirect URL” is the link that Google will return the user to after you’ve successfully logged them in. For instance, you might return them to your original link or redirect them to a different link. You’ll need to add the URL here.&lt;/p&gt;

&lt;p&gt;Add the following URLs to the authorized javaScript origins and authorized redirect URLs: &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; and &lt;a href="http://localhost" rel="noopener noreferrer"&gt;http://localhost&lt;/a&gt;, respectively:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709653232897_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709653232897_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create a web client ID, you will need to click the “CREATE” button. You will be returned to the homepage, where you can view your freshly created credentials.  To copy your new web client ID, hit the Copy icon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709653310113_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709653310113_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we've successfully built our web client ID, we'll go into our React app and integrate the Google login.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing Google OAuth into the React App
&lt;/h2&gt;

&lt;p&gt;Inside our &lt;code&gt;index.js&lt;/code&gt; file, we'll add the &lt;code&gt;clientId&lt;/code&gt; and it’s value which was created earlier on below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import { GoogleOAuthProvider } from '@react-oauth/google';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  &amp;lt;GoogleOAuthProvider clientId='589485744384-0fb486jrn0oi8sts047cucnkp86d5f2s.apps.googleusercontent.com'&amp;gt;
  &amp;lt;React.StrictMode&amp;gt;
    &amp;lt;App /&amp;gt;
  &amp;lt;/React.StrictMode&amp;gt;
  &amp;lt;/GoogleOAuthProvider&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you test this code in your browser, here's how it looks:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709655373597_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709655373597_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Although it looks same, but when you click the Sign in with Google button, a consent page or popup will appear, as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709655415466_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709655415466_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To establish a user profile within our application, let's move one step ahead and gather information from the user email. The app will redirect the user to the homepage and then display their email, name, and image.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a user login based on the user's Google account.
&lt;/h3&gt;

&lt;p&gt;You can access the user's profile, which includes their name, email address, image, access token and so on when you integrate Google login into your app. In order to create a user profile, we will use the user's email information.&lt;/p&gt;

&lt;p&gt;Let's replace this code with the following in our &lt;code&gt;app.js&lt;/code&gt; component:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//App.js//
import { jwtDecode } from "jwt-decode";
import {GoogleLogin } from '@react-oauth/google';

function App() {
      ....
  return (

&amp;lt;div className='App' &amp;gt;
      &amp;lt;h2&amp;gt;React Google Sign-In&amp;lt;/h2&amp;gt;
            &amp;lt;GoogleLogin
            className="sign"
  onSuccess={credentialResponse =&amp;gt; {
    const details= jwtDecode(credentialResponse.credential);
    console.log(details);
    console.log(credentialResponse);
  }}
  onError={() =&amp;gt; {
    console.log('Login Failed');
  }}
/&amp;gt;    &amp;lt;/div&amp;gt;
  );
}
export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We installed a  &lt;code&gt;jwt-decode&lt;/code&gt; library to decode the JWT (JSON Web Token) received from Google after successful sign-in. The decoded token details, such as name, email address, locale, etc., are logged into the console along with the credential response. So whenever we sign in, our details are logged in the console, just like  we have below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709722573384_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_CF9C8B1E97A894E9C5EA9AA58AEEA1211BC4ED420126CDA200FD192B1A27C16C_1709722573384_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will use this information to establish a user profile whereby we only need The profile picture, name, and email address. Yet again, we make some modifications; instead of logging the details on the console, we get them displayed on the page.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//App.js//
import { jwtDecode } from "jwt-decode";
import {GoogleLogin } from '@react-oauth/google';

function App() {
  const [userData, setUserData] = useState(null);
  return (
    &amp;lt;div className='App'&amp;gt;
      &amp;lt;h2&amp;gt;React Google Sign-In&amp;lt;/h2&amp;gt;
      {!userData &amp;amp;&amp;amp; (
        &amp;lt;GoogleLogin
          className="sign"
          onSuccess={credentialResponse =&amp;gt; {
            const details = jwtDecode(credentialResponse.credential);
            const userData = {
              picture: details.picture,
              name: details.name,
              email: details.email
            };
            setUserData(userData);
          }}
          onError={() =&amp;gt; {
            console.log('Login Failed');
          }}
        /&amp;gt;
      )}
      {userData &amp;amp;&amp;amp; (
        &amp;lt;div&amp;gt;
          &amp;lt;h3&amp;gt;Logged in&amp;lt;/h3&amp;gt;
          &amp;lt;img src={userData.picture} alt="Profile" /&amp;gt;
          &amp;lt;h3&amp;gt;Name: {userData.name}&amp;lt;/h3&amp;gt;
          &amp;lt;p&amp;gt;Email: {userData.email}&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
      )}
    &amp;lt;/div&amp;gt;
  );
}
export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this modified code, the &lt;code&gt;userData&lt;/code&gt; state variable is updated with the profile picture URL, name, and email address extracted from the decoded JWT. The &lt;code&gt;userData&lt;/code&gt; is then used to render the profile picture, name, and email address in the React app. So whenever we sign in, we get our data displayed as below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdftr18e0h6q1p698gv21.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdftr18e0h6q1p698gv21.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Google OAuth integration in your React app can greatly improve the user experience by providing a secure and effective signing process. We've covered the essentials, such as configuring the OAuth consent page and obtaining your Google client ID, to customize the login experience and manage user sessions. By using the @react-oauth/google package, you can add advanced features like One Tap login and tailor the authentication flow to your app's specific requirements, creating a user-friendly and secure authentication experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;React&lt;/li&gt;
&lt;li&gt;OAuth Google&lt;/li&gt;
&lt;li&gt;JWT Decode&lt;/li&gt;
&lt;li&gt;GitHub Repo&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
  </channel>
</rss>
