From 1a51eccdd115789a96eeb81b2cb322dc593a67ce Mon Sep 17 00:00:00 2001 From: Jason Robbins Date: Thu, 27 May 2021 09:20:42 -0700 Subject: [PATCH] Simplify the on-page JS for signIn and signOut (#1332) * progress * Added catch() for case where sign-in fails. --- static/js-src/cs-client.js | 18 ++++++++++++- templates/_base.html | 52 ++++++++++++-------------------------- templates/header.html | 14 +++++++++- 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/static/js-src/cs-client.js b/static/js-src/cs-client.js index 1259bc09..70073267 100644 --- a/static/js-src/cs-client.js +++ b/static/js-src/cs-client.js @@ -92,7 +92,7 @@ class ChromeStatusClient { if (response.status !== 200) { throw new Error( - `Got error response from server: ${response.status}`); + `Got error response from server ${resource}: ${response.status}`); } const rawResponseText = await response.text(); const XSSIPrefix = ')]}\'\n'; @@ -131,6 +131,22 @@ class ChromeStatusClient { // ////////////////////////////////////////////////////////////// // Specific API calls + // Signing in and out + + signIn(googleUser) { + // TODO(jrobbins): Consider using profile pic. + // let profile = googleUser.getBasicProfile(); + let idToken = googleUser.getAuthResponse().id_token; + // We don't use doPost because we don't already have a XSRF token. + return this.doFetch('/login', 'POST', {'id_token': idToken}, false); + } + + signOut(auth2) { + return auth2.signOut().then(() => { + return this.doPost('/logout'); + }); + } + // Cues API dismissCue(cue) { diff --git a/templates/_base.html b/templates/_base.html index 813acfd0..c7736323 100644 --- a/templates/_base.html +++ b/templates/_base.html @@ -65,45 +65,25 @@ limitations under the License. +{% endif %}