Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
Await GoogleAuth to finish initialization (#382)
Browse files Browse the repository at this point in the history
* Await GoogleAuth to finish initialization

* fixed logout

* ignore if unmounted
  • Loading branch information
ranihorev authored Oct 19, 2020
1 parent 6f59a2e commit a8f39eb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
26 changes: 19 additions & 7 deletions src/use-google-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,25 @@ const useGoogleLogin = ({
onFailure(err)
}
)
} else if (isSignedIn && GoogleAuth.isSignedIn.get()) {
setLoaded(true)
onAutoLoadFinished(true)
handleSigninSuccess(GoogleAuth.currentUser.get())
} else if (!unmounted) {
setLoaded(true)
onAutoLoadFinished(false)
} else {
GoogleAuth.then(
() => {
if (unmounted) {
return
}
if (isSignedIn && GoogleAuth.isSignedIn.get()) {
setLoaded(true)
onAutoLoadFinished(true)
handleSigninSuccess(GoogleAuth.currentUser.get())
} else {
setLoaded(true)
onAutoLoadFinished(false)
}
},
err => {
onFailure(err)
}
)
}
})
})
Expand Down
7 changes: 6 additions & 1 deletion src/use-google-logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ const useGoogleLogout = ({
if (window.gapi) {
const auth2 = window.gapi.auth2.getAuthInstance()
if (auth2 != null) {
auth2.signOut().then(auth2.disconnect().then(onLogoutSuccess))
auth2.then(
() => {
auth2.signOut().then(auth2.disconnect().then(onLogoutSuccess))
},
err => onFailure(err)
)
}
}
}
Expand Down

0 comments on commit a8f39eb

Please sign in to comment.