From f88bef15ed57c36dc33d220c8cdf1d5021b8fdbb Mon Sep 17 00:00:00 2001
From: Rob Vermaas <rob.vermaas@gmail.com>
Date: Mon, 13 Mar 2023 16:44:09 +0100
Subject: [PATCH] Use new Google for Web signin, the old way will be deprecated
 Mar 31st 2023

---
 src/root/auth.tt   | 5 +----
 src/root/topbar.tt | 6 ++++--
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/root/auth.tt b/src/root/auth.tt
index 360904d9..d1539765 100644
--- a/src/root/auth.tt
+++ b/src/root/auth.tt
@@ -82,7 +82,7 @@
       function onGoogleSignIn(googleUser) {
         requestJSON({
           url: "[% c.uri_for('/google-login') %]",
-          data: "id_token=" + googleUser.getAuthResponse().id_token,
+          data: "id_token=" + googleUser.credential,
           type: 'POST',
           success: function(data) {
             window.location.reload();
@@ -91,9 +91,6 @@
         return false;
         };
 
-      $("#google-signin").click(function() {
-        $(".g-signin2:first-child > div").click();
-      });
     </script>
   [% END %]
 
diff --git a/src/root/topbar.tt b/src/root/topbar.tt
index fdfbf431..1771222d 100644
--- a/src/root/topbar.tt
+++ b/src/root/topbar.tt
@@ -133,8 +133,10 @@
   [% ELSE %]
     [% WRAPPER makeSubMenu title="Sign in" id="sign-in-menu" align="right" %]
       [% IF c.config.enable_google_login %]
-        <div style="display: none" class="g-signin2" data-onsuccess="onGoogleSignIn" data-theme="dark"></div>
-        <a class="dropdown-item" href="#" id="google-signin">Sign in with Google</a>
+        <script src="https://accounts.google.com/gsi/client" async defer></script>
+        <div id="g_id_onload" data-client_id="[% c.config.google_client_id %]" data-callback="onGoogleSignIn">
+        </div>
+        <div class="g_id_signin" data-type="standard"></div>
         <div class="dropdown-divider"></div>
       [% END %]
       [% IF c.config.github_client_id %]