Skip to content

Commit 58b7981

Browse files
committed
Modify googleLogin
1 parent beee70a commit 58b7981

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/commons/sagas/PersistenceSaga.tsx

+17-11
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,23 @@ const MIME_SOURCE = 'text/plain';
4242
// GIS Token Client
4343
let googleProvider: GoogleOAuthProvider;
4444
// Login function
45-
const googleLogin = () =>
46-
new Promise<SuccessTokenResponse>((resolve, reject) => {
47-
googleProvider.useGoogleLogin({
48-
flow: 'implicit',
49-
onSuccess: resolve,
50-
scope: SCOPES
51-
})();
52-
});
45+
function* googleLogin() {
46+
try {
47+
const tokenResp: SuccessTokenResponse = yield new Promise<SuccessTokenResponse>(
48+
(resolve, reject) => {
49+
googleProvider.useGoogleLogin({
50+
flow: 'implicit',
51+
onSuccess: resolve,
52+
onError: reject,
53+
scope: SCOPES
54+
})();
55+
}
56+
);
57+
yield call(handleUserChanged, tokenResp.access_token);
58+
} catch (ex) {
59+
console.error(ex);
60+
}
61+
}
5362

5463
export function* persistenceSaga(): SagaIterator {
5564
yield takeLatest(LOGOUT_GOOGLE, function* (): any {
@@ -62,7 +71,6 @@ export function* persistenceSaga(): SagaIterator {
6271
yield takeLatest(LOGIN_GOOGLE, function* (): any {
6372
yield call(ensureInitialised);
6473
yield call(googleLogin);
65-
yield call(handleUserChanged, gapi.client.getToken().access_token);
6674
});
6775

6876
yield takeEvery(PERSISTENCE_INITIALISE, function* (): any {
@@ -386,14 +394,12 @@ function* ensureInitialisedAndAuthorised() {
386394

387395
if (currToken === null) {
388396
yield call(googleLogin);
389-
yield call(handleUserChanged, gapi.client.getToken().access_token);
390397
} else {
391398
// check if loaded token is still valid
392399
const email: string | undefined = yield call(getUserProfileDataEmail);
393400
const isValid = email ? true : false;
394401
if (!isValid) {
395402
yield call(googleLogin);
396-
yield call(handleUserChanged, gapi.client.getToken().access_token);
397403
}
398404
}
399405
}

0 commit comments

Comments
 (0)