diff --git a/index.html b/index.html
index 6b86d47..d37e766 100644
--- a/index.html
+++ b/index.html
@@ -1108,24 +1108,20 @@
Sign in with your official Google account to share your feedback. Your verified Google photo and Gmail will automatically link to your review.
-
-
-
-
+
+
+
+
+
+
+
+ Direct Google Account Sign-In
+
@@ -3439,42 +3435,16 @@ response = client.chat.completions.create(
loadReviews();
}
- // Initialize Google Identity Services
- function initGoogleIdentity() {
- if (window.google && google.accounts && google.accounts.id) {
- try {
- google.accounts.id.initialize({
- client_id: GOOGLE_CLIENT_ID,
- callback: handleGoogleCredentialResponse,
- auto_select: false,
- cancel_on_tap_outside: true
- });
-
- // Render official Google button inside container
- const btnContainer = document.getElementById("gsi-btn-container");
- if (btnContainer) {
- google.accounts.id.renderButton(btnContainer, {
- theme: "outline",
- size: "large",
- type: "standard",
- shape: "pill",
- text: "continue_with",
- logo_alignment: "left",
- width: 280
- });
- }
- } catch(e) {
- console.log("GSI init note:", e);
- }
- } else {
- // Retry after GSI script finishes loading
- setTimeout(initGoogleIdentity, 500);
- }
- }
+ let tokenClient = null;
// Handle real Google JWT Credential Response
- function handleGoogleCredentialResponse(response) {
+ window.handleGoogleCredentialResponse = function(response) {
+ console.log("Google Credential Response received:", response);
try {
+ if (!response || !response.credential) {
+ console.error("No credential in response", response);
+ return;
+ }
// Decode standard JWT
const base64Url = response.credential.split('.')[1];
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
@@ -3490,13 +3460,88 @@ response = client.chat.completions.create(
};
localStorage.setItem("aira_google_user", JSON.stringify(currentUser));
- renderUserAuthUI();
+ renderUserAuthUI();
} catch(err) {
console.error("Failed to decode Google token:", err);
alert("Google sign-in completed, but failed to parse profile. Please try again.");
}
+ };
+
+ // Initialize Google Identity Services & OAuth 2.0 Token Client
+ function initGoogleIdentity() {
+ if (window.google && google.accounts) {
+ try {
+ // 1. Initialize Google Identity Services Credential API
+ if (google.accounts.id) {
+ google.accounts.id.initialize({
+ client_id: GOOGLE_CLIENT_ID,
+ callback: window.handleGoogleCredentialResponse,
+ auto_select: false,
+ cancel_on_tap_outside: true,
+ itp_support: true
+ });
+
+ const btnContainer = document.getElementById("gsi-btn-container");
+ if (btnContainer) {
+ btnContainer.innerHTML = "";
+ google.accounts.id.renderButton(btnContainer, {
+ theme: "outline",
+ size: "large",
+ type: "standard",
+ shape: "pill",
+ text: "signin_with",
+ logo_alignment: "left",
+ width: 280
+ });
+ }
+ }
+
+ // 2. Initialize OAuth 2.0 Token Client (Direct Account Picker - bypasses FedCM/white-screen)
+ if (google.accounts.oauth2) {
+ tokenClient = google.accounts.oauth2.initTokenClient({
+ client_id: GOOGLE_CLIENT_ID,
+ scope: 'email profile openid',
+ callback: async (tokenResponse) => {
+ if (tokenResponse && tokenResponse.access_token) {
+ try {
+ const res = await fetch("https://www.googleapis.com/oauth2/v3/userinfo", {
+ headers: { Authorization: `Bearer ${tokenResponse.access_token}` }
+ });
+ if (res.ok) {
+ const profile = await res.json();
+ currentUser = {
+ name: profile.name || "Google User",
+ email: profile.email,
+ picture: profile.picture || `https://api.dicebear.com/7.x/initials/svg?seed=${encodeURIComponent(profile.name || "User")}`
+ };
+ localStorage.setItem("aira_google_user", JSON.stringify(currentUser));
+ renderUserAuthUI();
+ }
+ } catch(err) {
+ console.error("UserInfo fetch error:", err);
+ }
+ }
+ }
+ });
+ }
+ } catch(e) {
+ console.log("GSI init note:", e);
+ }
+ } else {
+ setTimeout(initGoogleIdentity, 300);
+ }
}
+ window.triggerGoogleOAuth = function() {
+ if (tokenClient) {
+ tokenClient.requestAccessToken({ prompt: 'select_account' });
+ } else if (window.google && google.accounts && google.accounts.id) {
+ google.accounts.id.prompt();
+ } else {
+ alert("Google Services loading... please wait a moment and try again.");
+ }
+ };
+
function renderUserAuthUI() {
const loggedOutBox = document.getElementById("google-feedback-loggedout");
const loggedInBox = document.getElementById("google-feedback-loggedin");