Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react google login

npm install react-google-login
Comment

react google login

// npm install react-google-login

import React from 'react';
import ReactDOM from 'react-dom';
import GoogleLogin from 'react-google-login';
// or
import { GoogleLogin } from 'react-google-login';


const responseGoogle = (response) => {
  console.log(response);
}

ReactDOM.render(
  <GoogleLogin
    clientId="658977310896-knrl3gka66fldh83dao2rhgbblmd4un9.apps.googleusercontent.com"
    buttonText="Login"
    onSuccess={responseGoogle}
    onFailure={responseGoogle}
    cookiePolicy={'single_host_origin'}
  />,
  document.getElementById('googleButton')
);
Comment

login with google in react

import React, { useState } from "react";
import google from './assets/images/google.png'
import './assets/css/all.css'
import './assets/css/bootstrap.min.css'
import './assets/css/responsive.css'
import './assets/css/style.css'
import ReactDOM from "react-dom";
import { GoogleLogin, GoogleLogout } from "react-google-login";
const GoogleLoginPage = () => {
  const client_id =
    "233345635594-km0tlqqrv2difnjgovf2jn11sgg7117c.apps.googleusercontent.com";
  const [showLoginButton, setLoginButton] = useState(true);
  const [showLogoutButton, setLogoutButton] = useState(false);
  const loginHandler = (res) => {
    console.log("res", res.profileObj);
    console.log("this is my")
    setLoginButton(false);
    setLogoutButton(true);
  };
  const failureHandler = (res) => {
    console.log("login failed", res);
  };
  const logoutHandler = (res) => {
    alert("logout sucessfully");
    setLoginButton(true);
    setLogoutButton(false);
  };
  return (
    <>
      {showLoginButton && (
        <>
          {/* <GoogleLogin
              className="google-item"            
              clientId={client_id}
              onSuccess={loginHandler}
              onFailure={failureHandler}
              cookiePolicy={"single_host_origin"}
            /> */}
          <GoogleLogin
            clientId={client_id}
            render={(renderProps) => (
              <button
                className="btn button btn-outline"
                onClick={renderProps.onClick}
                // disabled={renderProps.disabled}
              >
                <img src={google} /> Sign Up with Google
              </button>
            )}
            onSuccess={loginHandler}
            onFailure={failureHandler}
            cookiePolicy={"single_host_origin"}
          />
        </>
      )}
      {showLogoutButton && (
        <GoogleLogout
          clientId={client_id}
          render={(renderProps) => (
            <button
              className="btn button btn-outline"
              onClick={renderProps.onClick}
              // disabled={renderProps.disabled}
            >
              <img src={google} /> logout 
            </button>
          )}
          onLogoutSuccess={logoutHandler}
        ></GoogleLogout>
      )}
    </>
  );
};
export default GoogleLoginPage;
Comment

react-google-login

import React from 'react';
import ReactDOM from 'react-dom';
import GoogleLogin from 'react-google-login';
// or
import { GoogleLogin } from 'react-google-login';

import { gapi } from "gapi-script";


const responseGoogle = (response) => {
  console.log(response);
}

ReactDOM.render(
  <GoogleLogin
    clientId="658977310896-knrl3gka66fldh83dao2rhgbblmd4un9.apps.googleusercontent.com"
    buttonText="Login"
    onSuccess={responseGoogle}
    onFailure={responseGoogle}
    cookiePolicy={'single_host_origin'}
  />,
  document.getElementById('googleButton')
);
Comment

PREVIOUS NEXT
Code Example
Javascript :: replace char at index of string 
Javascript :: prettier printWidth 
Javascript :: push javascript 
Javascript :: javascript replace tag 
Javascript :: enzyme react 
Javascript :: window location 
Javascript :: javascript array destructuring last element 
Javascript :: expo dependencies 
Javascript :: simple javascript 
Javascript :: see if array contains array javascript 
Javascript :: jquery get all data attributes values 
Javascript :: javascript inheritence 
Javascript :: react: fow to use find(to get the id of a element 
Javascript :: get file css code with javascript 
Javascript :: javascript loop counter 
Javascript :: stringify vs parse 
Javascript :: node js mongoose text index 
Javascript :: react native material bottom tabs 
Javascript :: js objects 
Javascript :: leaflet marker 
Javascript :: Iterate Through the Keys of an Object 
Javascript :: Get last item on js array 
Javascript :: custom processing datatables 
Javascript :: select jquery display none 
Javascript :: 10 javascript interview questions 
Javascript :: react multiple classnames 
Javascript :: sequelize findall 
Javascript :: javascript export 
Javascript :: js download 
Javascript :: vue cli tailwind config 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =