Skip to content

Commit

Permalink
fix isSignedIn bug
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyjgrove committed May 13, 2020
1 parent 6458411 commit 2f145c7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/use-google-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ const useGoogleLogin = ({
e.preventDefault() // to prevent submit if used within form
}
if (loaded) {
const auth2 = window.gapi.auth2.getAuthInstance()
const GoogleAuth = window.gapi.auth2.getAuthInstance()
const options = {
prompt
}
onRequest()
if (responseType === 'code') {
auth2.grantOfflineAccess(options).then(
GoogleAuth.grantOfflineAccess(options).then(
res => onSuccess(res),
err => onFailure(err)
)
} else {
auth2.signIn(options).then(
GoogleAuth.signIn(options).then(
res => handleSigninSuccess(res),
err => onFailure(err)
)
Expand Down Expand Up @@ -91,7 +91,8 @@ const useGoogleLogin = ({
}

window.gapi.load('auth2', () => {
if (!window.gapi.auth2.getAuthInstance()) {
const GoogleAuth = window.gapi.auth2.getAuthInstance()
if (!GoogleAuth) {
window.gapi.auth2.init(params).then(
res => {
if (!unmounted) {
Expand All @@ -109,10 +110,10 @@ const useGoogleLogin = ({
onFailure(err)
}
)
} else if (isSignedIn && window.gapi.auth2.isSignedIn.get()) {
} else if (isSignedIn && GoogleAuth.isSignedIn.get()) {
setLoaded(true)
onAutoLoadFinished(true)
handleSigninSuccess(window.gapi.auth2.currentUser.get())
handleSigninSuccess(GoogleAuth.currentUser.get())
} else if (!unmounted) {
setLoaded(true)
onAutoLoadFinished(false)
Expand Down

0 comments on commit 2f145c7

Please sign in to comment.