React-google-login: Uncaught TypeError: Cannot read property 'load' of undefined

Created on 14 Apr 2020  路  10Comments  路  Source: anthonyjgrove/react-google-login

Experienced when using the hook like so:

/* useGoogleLogin.js */
import { useGoogleLogin } from 'react-google-login'

import config from 'config'

import { useActions, GoogleActions } from 'modules'

const SCOPES = [
  'email',
  'profile',
  'openid',
  //... a few more scopes
]

export default () => {
  const actions = useActions({
    googleLoginSuccess: GoogleActions.googleLoginSuccess,
    googleLoginPending: GoogleActions.googleLoginPending,
    googleLoginFailed: GoogleActions.googleLoginFailed,
  })

  return useGoogleLogin({
    clientId: config.GOOGLE_CLIENTID,
    cookiePolicy: 'single_host_origin',
    scope: SCOPES.join(' '),
    onSuccess: actions.googleLoginSuccess,
    onFailure: actions.googleLoginFailed,
    onRequest: actions.googleLoginPending,
  })
}
/* SomeComponent.js */
import useGoogleLogin from './useGoogleLogin.js'

const SomeComponent () => {
  const { signIn, loaded } = useGoogleLogin()

  if (!loaded) return null
  else return <button onClick={signIn}>Sign in</button>
}

The component version is being used elsewhere in the application without issue. Let me know what other information you need to debug.

Most helpful comment

done, v5.1.10

All 10 comments

You've been able to solve the issue, @Nfinished ?

I have not.

I'll go with the GoogleLogin component and wait for the fix then, ty!

I had the same problem, and i have found the reason why this happens.

The hook does not by default set the jsSrc.
If you do the following it should work:

return useGoogleLogin({
    clientId: config.GOOGLE_CLIENTID,
    cookiePolicy: 'single_host_origin',
    scope: SCOPES.join(' '),
    onSuccess: actions.googleLoginSuccess,
    onFailure: actions.googleLoginFailed,
    onRequest: actions.googleLoginPending,
    jsSrc: 'https://apis.google.com/js/api.js'
  })

I had the same problem, and i have found the reason why this happens.

The hook does not by default set the jsSrc.
If you do the following it should work:

return useGoogleLogin({
    clientId: config.GOOGLE_CLIENTID,
    cookiePolicy: 'single_host_origin',
    scope: SCOPES.join(' '),
    onSuccess: actions.googleLoginSuccess,
    onFailure: actions.googleLoginFailed,
    onRequest: actions.googleLoginPending,
    jsSrc: 'https://apis.google.com/js/api.js'
  })

Thank you! This was the solution, I'll throw up a pr

pls push new version to npm

done, v5.1.10

I still have this problem. Do you think running this inside a chrome extension/iframe could be the reason?

@BjoernRave did you make it work inside the chrome extension? Even i'm struggling with the same.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anthonyjgrove picture anthonyjgrove  路  8Comments

tameem92 picture tameem92  路  3Comments

pulkit-max picture pulkit-max  路  8Comments

zoripong picture zoripong  路  7Comments

MitulGedeeya picture MitulGedeeya  路  3Comments