1.0.4 • Published 1 year ago

@gojilabs/react-google-identity v1.0.4

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

@gojilabs/react-google-identity

Simple react hook to handle authentication with Google identity services

Installation

npm install @gojilabs/react-google-identity

or

yarn add @gojilabs/react-google-identity

Usage

import { useGoogleIdentity } from '@gojilabs/react-google-identity'
...

const MyComponent:FC = () => {
    const { buttonRef, ready } = useGoogleIdentity({ clientId: YOUR_GOOGLE_CLIENT_ID, callback: googleCallback })
...

    return <div ref={buttonRef} />
}

Hook takes config object, where you should pass YOUR_GOOGLE_CLIENT_ID, and callback, which will be fired when you complete google sign-in.

!!!WARNING

Since callback will be used as useEffect dependency, it should be wrapped with useCallback hook.

useGoogleIdentity returns object, with properties:

  • buttonRef - react ref, should be passed to div, where login button should be placed
  • ready - boolean flag, which represents whether google identity script was loaded or not