c4b149d Sep 30, 2018
1 contributor

Users who have contributed to this file

43 lines (34 sloc) 1.25 KB

Google Sign-in for Websites

React wrapper for Google Sign-In for Websites.


First use createGoogleAuthContext to create your context components. You need to obtain Google app client_id from here.

Then wrap your entire app with <Provider> component and anywhere in your app use the <Consumer> component.

import {createGoogleAuthContext} from 'libreact/lib/GoogleAuth';

const {Provider, Conumer} = createGoogleAuthContext({
  client_id: '',

  <Consumer>{({loading, signIn, signOut, isSignedIn, user}) => {
    if (loading) {
      return 'Loading...';
    console.log('user', user);
    return (
        <button onClick={isSignedIn ? signOut : signIn}>
          {isSignedIn ? 'Log out' : 'Sign in with Google!'}
        <div>Is signed in: {isSignedIn ? 'true' : 'false'}</div>
        {user &&
            <div>Name: {user.getBasicProfile().getName()}</div>
            <div>JWT: {user.getAuthResponse().id_token}</div>