Skip to content

Commit 46be7d6

Browse files
sumomomomomolinedoestrolling
authored andcommitted
Fix packages + use gapi.client to fetch email
1 parent 222d754 commit 46be7d6

File tree

4 files changed

+12
-29
lines changed

4 files changed

+12
-29
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"@szhsin/react-menu": "^4.0.0",
4141
"@tanstack/react-table": "^8.9.3",
4242
"@tremor/react": "^1.8.2",
43-
"@types/google.accounts": "^0.0.14",
4443
"ace-builds": "^1.4.14",
4544
"acorn": "^8.9.0",
4645
"ag-grid-community": "^31.0.0",
@@ -107,9 +106,9 @@
107106
"@testing-library/user-event": "^14.4.3",
108107
"@types/acorn": "^6.0.0",
109108
"@types/gapi": "^0.0.44",
110-
"@types/gapi.auth2": "^0.0.57",
111109
"@types/gapi.client": "^1.0.5",
112110
"@types/gapi.client.drive": "^3.0.14",
111+
"@types/google.accounts": "^0.0.14",
113112
"@types/google.picker": "^0.0.39",
114113
"@types/jest": "^29.0.0",
115114
"@types/js-yaml": "^4.0.5",

src/commons/sagas/PersistenceSaga.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
PERSISTENCE_SAVE_FILE_AS,
1111
PersistenceFile
1212
} from '../../features/persistence/PersistenceTypes';
13-
import { getUserProfileDataEmail } from '../../features/persistence/PersistenceUtils';
1413
import { store } from '../../pages/createStore';
1514
import { OverallState } from '../application/ApplicationTypes';
1615
import { ExternalLibraryName } from '../application/types/ExternalTypes';
@@ -31,6 +30,7 @@ const DISCOVERY_DOCS = ['https://www.googleapis.com/discovery/v1/apis/drive/v3/r
3130
const SCOPES =
3231
'profile https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/userinfo.email';
3332
const UPLOAD_PATH = 'https://www.googleapis.com/upload/drive/v3/files';
33+
const USER_INFO_PATH = 'https://www.googleapis.com/oauth2/v3/userinfo';
3434

3535
// Special ID value for the Google Drive API.
3636
const ROOT_ID = 'root';
@@ -370,7 +370,7 @@ function* handleUserChanged(accessToken: string | null) {
370370
if (accessToken === null) {
371371
yield put(actions.removeGoogleUserAndAccessToken());
372372
} else {
373-
const email: string | undefined = yield call(getUserProfileDataEmail, accessToken);
373+
const email: string | undefined = yield call(getUserProfileDataEmail);
374374
if (!email) {
375375
yield put(actions.removeGoogleUserAndAccessToken());
376376
} else {
@@ -415,14 +415,21 @@ function* ensureInitialisedAndAuthorised() {
415415
yield call(getToken);
416416
} else {
417417
// check if loaded token is still valid
418-
const email: string | undefined = yield call(getUserProfileDataEmail, currToken.access_token);
418+
const email: string | undefined = yield call(getUserProfileDataEmail);
419419
const isValid = email ? true : false;
420420
if (!isValid) {
421421
yield call(getToken);
422422
}
423423
}
424424
}
425425

426+
function getUserProfileDataEmail(): Promise<string | undefined> {
427+
return gapi.client.request({
428+
path: USER_INFO_PATH
429+
}).then(r => r.result.email)
430+
.catch(() => undefined);
431+
}
432+
426433
type PickFileResult =
427434
| { id: string; name: string; mimeType: string; parentId: string; picked: true }
428435
| { picked: false };

src/features/persistence/PersistenceUtils.tsx

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

yarn.lock

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,13 +2879,6 @@
28792879
"@types/qs" "*"
28802880
"@types/serve-static" "*"
28812881

2882-
"@types/gapi.auth2@^0.0.57":
2883-
version "0.0.57"
2884-
resolved "https://registry.yarnpkg.com/@types/gapi.auth2/-/gapi.auth2-0.0.57.tgz#5544a696d97fc979044d48a8bf7de5e2b35899b5"
2885-
integrity sha512-2nYF2OZlEqWvF5rLk0nrQlAkk51Abe9zLHvA85NZqpIauYT/TluDNsPWkncI969BR/Ts5mdKrXgiWE/f4N6mMQ==
2886-
dependencies:
2887-
"@types/gapi" "*"
2888-
28892882
"@types/gapi.client.discovery@*":
28902883
version "1.0.9"
28912884
resolved "https://registry.yarnpkg.com/@types/gapi.client.discovery/-/gapi.client.discovery-1.0.9.tgz#e2472989baa01f2e32a2d5a80981da8513f875ae"
@@ -2905,7 +2898,7 @@
29052898
resolved "https://registry.yarnpkg.com/@types/gapi.client/-/gapi.client-1.0.8.tgz#8e02c57493b014521f2fa3359166c01dc2861cd7"
29062899
integrity sha512-qJQUmmumbYym3Amax0S8CVzuSngcXsC1fJdwRS2zeW5lM63zXkw4wJFP+bG0jzgi0R6EsJKoHnGNVTDbOyG1ng==
29072900

2908-
"@types/gapi@*", "@types/gapi@^0.0.44":
2901+
"@types/gapi@^0.0.44":
29092902
version "0.0.44"
29102903
resolved "https://registry.yarnpkg.com/@types/gapi/-/gapi-0.0.44.tgz#f097f7a0f59d63a59098a08a62a560ca168426fb"
29112904
integrity sha512-hsgJMfZ/pMwI15UlAYHMNwj8DRoigo1odhbPwEXdp19ZQwQAXbcRrpzaDsfc+9XM6RtGpvl4Ja7uW8A+KPCa7w==

0 commit comments

Comments
 (0)