Login con Google

Contactar con el profesor

Crearemos un nuevo proyecto en https://console.developers.google.com/apis/dashboard

→ credentials → Create credentials → Copiamos el client ID

import { useState  } from 'react';
import GoogleLogin from 'react-google-login';

export default () => {
    const [user, setUser] = useState(null);
    const [accessToken, setAccessToken] = useState(null);


    const onSuccess = ({ accessToken, profileObj }) => {
        setUser(profileObj);
        setAccessToken(accessToken);
    }

    return (
        <div>
            <GoogleLogin
                clientId="357372979990-h0j....apps.googleusercontent.com"
                buttonText="Login"
                onSuccess={onSuccess}
                onFailure={(err) => console.log(err)}
                cookiePolicy={'single_host_origin'}
            />
            {accessToken && <div>{accessToken}</div>}
            {user && <div>{user.name}</div>    }
            {user && <img src={user.imageUrl} /> }
        </div> 
        );
};

← React Developer Tool
Login en React →

Aviso Legal | Política de privacidad