Reputation: 31
I am trying to implement Google API integration to signin and out of the application. I am using react library react-google-login for it
<GoogleLogin>
is working fine . But when i tried to logout it just setting the state out. From the below code one can understand that
<GoogleLogout
buttonText="Logout"
onLogoutSuccess={(response) => { this.setState(() => { return { isSignedIn: false } }) }}
></GoogleLogout>
Instead i want to logout the user completely from google itself.
Upvotes: 2
Views: 3865
Reputation: 87
I had the same issue, and as a work around ,so then I installed gapi-script and added a button:
<button type="button" class="btn btn-danger btn-sm" onClick={this.logout}>
Logout
</button>
And on click I do this:
logout (response) {
this.setState(state => ({
isLogined: false,
accessToken: ''
}));
const auth2 = gapi.auth2.getAuthInstance();
if (auth2 != null) {
auth2.signOut().then(
auth2.disconnect().then(console.log('LOGOUT SUCCESSFUL'))
)
}
}
Upvotes: 1
Reputation: 26
From your code and the document of react-google-login, maybe you miss some required props? You should provide three required props to <GoogleLogout>
: clientId
, onLogoutSuccess
and onFailure
. There is the source: https://github.com/anthonyjgrove/react-google-login#logout-props
Upvotes: 1