Skip to content

Commit 934e58b

Browse files
abereghiciAlexandru BereghiciMomenSherif
authored
fix: improved definition types and added a missing callback function in TokenResponse type (#199)
* fix: improved definition types and added a missing callback function in TokenResponse type * chore: added patch update * fix: re export types --------- Co-authored-by: Alexandru Bereghici <abereghici@tripadvisor.com> Co-authored-by: Mo'men Sherif <momensherif.2019@gmail.com>
1 parent 4559cdb commit 934e58b

File tree

6 files changed

+72
-60
lines changed

6 files changed

+72
-60
lines changed

.changeset/friendly-colts-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@react-oauth/google': patch
3+
---
4+
5+
Improved definition types. Added missing error_callback function in TokenResponse type"

.changeset/old-years-try.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/poor-beers-lie.md

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,54 @@
1-
interface Window {
2-
google?: {
3-
accounts: {
4-
id: {
5-
initialize: (input: IdConfiguration) => void;
6-
prompt: (momentListener?: MomentListener) => void;
7-
renderButton: (
8-
parent: HTMLElement,
9-
options: GsiButtonConfiguration,
10-
) => void;
11-
disableAutoSelect: () => void;
12-
storeCredential: (
13-
credential: { id: string; password: string },
14-
callback?: () => void,
15-
) => void;
16-
cancel: () => void;
17-
onGoogleLibraryLoad: Function;
18-
revoke: (accessToken: string, done: () => void) => void;
19-
};
20-
oauth2: {
21-
initTokenClient: (config: TokenClientConfig) => {
22-
requestAccessToken: (
23-
overridableClientConfig?: OverridableTokenClientConfig,
1+
import {
2+
IdConfiguration,
3+
MomentListener,
4+
GsiButtonConfiguration,
5+
TokenClientConfig,
6+
OverridableTokenClientConfig,
7+
CodeClientConfig,
8+
TokenResponse,
9+
} from './types';
10+
declare global {
11+
interface Window {
12+
google?: {
13+
accounts: {
14+
id: {
15+
initialize: (input: IdConfiguration) => void;
16+
prompt: (momentListener?: MomentListener) => void;
17+
renderButton: (
18+
parent: HTMLElement,
19+
options: GsiButtonConfiguration,
20+
) => void;
21+
disableAutoSelect: () => void;
22+
storeCredential: (
23+
credential: { id: string; password: string },
24+
callback?: () => void,
2425
) => void;
26+
cancel: () => void;
27+
onGoogleLibraryLoad: Function;
28+
revoke: (accessToken: string, done: () => void) => void;
2529
};
26-
initCodeClient: (config: CodeClientConfig) => {
27-
requestCode: () => void;
30+
oauth2: {
31+
initTokenClient: (config: TokenClientConfig) => {
32+
requestAccessToken: (
33+
overridableClientConfig?: OverridableTokenClientConfig,
34+
) => void;
35+
};
36+
initCodeClient: (config: CodeClientConfig) => {
37+
requestCode: () => void;
38+
};
39+
hasGrantedAnyScope: (
40+
tokenResponse: TokenResponse,
41+
firstScope: string,
42+
...restScopes: string[]
43+
) => boolean;
44+
hasGrantedAllScopes: (
45+
tokenResponse: TokenResponse,
46+
firstScope: string,
47+
...restScopes: string[]
48+
) => boolean;
49+
revoke: (accessToken: string, done?: () => void) => void;
2850
};
29-
hasGrantedAnyScope: (
30-
tokenResponse: TokenResponse,
31-
firstScope: string,
32-
...restScopes: string[]
33-
) => boolean;
34-
hasGrantedAllScopes: (
35-
tokenResponse: TokenResponse,
36-
firstScope: string,
37-
...restScopes: string[]
38-
) => boolean;
39-
revoke: (accessToken: string, done?: () => void) => void;
4051
};
4152
};
42-
};
53+
}
4354
}

packages/@react-oauth/google/src/hooks/useGoogleLogin.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,9 @@ import {
88
CodeClientConfig,
99
CodeResponse,
1010
OverridableTokenClientConfig,
11+
NonOAuthError,
1112
} from '../types';
1213

13-
export type NonOAuthError = {
14-
/**
15-
* Some non-OAuth errors, such as the popup window is failed to open;
16-
* or closed before an OAuth response is returned.
17-
* https://developers.google.com/identity/oauth2/web/reference/js-reference#TokenClientConfig
18-
* https://developers.google.com/identity/oauth2/web/reference/js-reference#CodeClientConfig
19-
*/
20-
type: 'popup_failed_to_open' | 'popup_closed' | 'unknown';
21-
};
22-
2314
interface ImplicitFlowOptions
2415
extends Omit<TokenClientConfig, 'client_id' | 'scope' | 'callback'> {
2516
onSuccess?: (

packages/@react-oauth/google/src/types/index.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
type Context = 'signin' | 'signup' | 'use';
1+
export type Context = 'signin' | 'signup' | 'use';
22

3-
type UxMode = 'popup' | 'redirect';
3+
export type UxMode = 'popup' | 'redirect';
44

5-
type ErrorCode =
5+
export type ErrorCode =
66
| 'invalid_request'
77
| 'access_denied'
88
| 'unauthorized_client'
@@ -160,6 +160,15 @@ export interface TokenResponse {
160160
error_uri?: string;
161161
}
162162

163+
export type NonOAuthError = {
164+
/**
165+
* Some non-OAuth errors, such as the popup window is failed to open;
166+
* or closed before an OAuth response is returned.
167+
* https://developers.google.com/identity/oauth2/web/reference/js-reference#TokenClientConfig
168+
* https://developers.google.com/identity/oauth2/web/reference/js-reference#CodeClientConfig
169+
*/
170+
type: 'popup_failed_to_open' | 'popup_closed' | 'unknown';
171+
};
163172
export interface TokenClientConfig {
164173
/**
165174
* The client ID for your application. You can find this value in the
@@ -180,6 +189,12 @@ export interface TokenClientConfig {
180189
*/
181190
callback?: (response: TokenResponse) => void;
182191

192+
/**
193+
* Optional. The JavaScript function that handles some non-OAuth errors,
194+
* such as the popup window is failed to open; or closed before an OAuth response is returned.
195+
*/
196+
error_callback?: (nonOAuthError: NonOAuthError) => void;
197+
183198
/**
184199
* Optional, defaults to 'select_account'. A space-delimited, case-sensitive list of prompts to present the user
185200
*/

0 commit comments

Comments
 (0)