Client ID: {clientId}
GSI Script: {scriptLoadedSuccessfully ? 'β
Loaded' : 'β³ Loadingβ¦'}
);
}
```
### Error Handling
- Throws an error if called outside of a `GoogleOAuthProvider`.
```
--------------------------------
### useGoogleLogin
Source: https://context7.com/momensherif/react-oauth/llms.txt
Provides a login trigger function to open the Google consent popup. Supports both implicit flow for direct token retrieval and authorization code flow for backend token exchange.
```APIDOC
## useGoogleLogin
### Description
Returns a login trigger function that opens the Google consent popup. Use `flow: 'implicit'` (default) to get an access token directly in the browser; use `flow: 'auth-code'` to receive an authorization code that your backend exchanges for tokens. The returned function for the implicit flow accepts optional `OverridableTokenClientConfig` at call-time to override `prompt`, `hint`, or `state`.
### Implicit Flow Example
```tsx
import { useGoogleLogin, hasGrantedAllScopesGoogle } from '@react-oauth/google';
import axios from 'axios';
function ImplicitLoginButton() {
const login = useGoogleLogin({
flow: 'implicit', // default
scope: 'https://www.googleapis.com/auth/calendar.readonly',
prompt: 'consent', // '' | 'none' | 'consent' | 'select_account'
hint: 'user@example.com',
onSuccess: async tokenResponse => {
// tokenResponse: { access_token, expires_in, scope, token_type, ... }
const calendarGranted = hasGrantedAllScopesGoogle(
tokenResponse,
'https://www.googleapis.com/auth/calendar.readonly',
);
if (!calendarGranted) {
console.warn('Calendar scope was not granted');
return;
}
const { data } = await axios.get(
'https://www.googleapis.com/calendar/v3/calendars/primary/events',
{ headers: { Authorization: `Bearer ${tokenResponse.access_token}` } },
);
console.log('Calendar events:', data.items);
},
onError: err => console.error('Login failed:', err.error, err.error_description),
onNonOAuthError: err => {
// err.type: 'popup_failed_to_open' | 'popup_closed' | 'unknown'
if (err.type === 'popup_closed') console.warn('User closed the popup');
},
});
return