From 27791d2a022e816ee5011d060dddc030efa1aa95 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 30 Dec 2025 12:49:05 -0800 Subject: [PATCH] Add error handling to Google sign-in flow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- static/app.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/static/app.js b/static/app.js index 151e4d5..c6a7f8f 100644 --- a/static/app.js +++ b/static/app.js @@ -97,15 +97,27 @@ export async function auth() { google.accounts.id.initialize({ client_id: CLIENT_ID, callback: async (response) => { - const res = await fetch('/auth/google/callback', { - method: 'POST', - headers: {'Content-Type': 'application/x-www-form-urlencoded'}, - body: 'credential=' + encodeURIComponent(response.credential) - }); - const profile = await res.json(); - setProfile(profile); - signin.style.display = 'none'; - resolve(profile); + try { + const res = await fetch('/auth/google/callback', { + method: 'POST', + headers: {'Content-Type': 'application/x-www-form-urlencoded'}, + body: 'credential=' + encodeURIComponent(response.credential) + }); + if (!res.ok) { + throw new Error(`server returned ${res.status}: ${await res.text()}`); + } + const profile = await res.json(); + setProfile(profile); + signin.style.display = 'none'; + resolve(profile); + } catch (err) { + console.error('sign-in callback error:', err); + alert('Sign-in failed: ' + err.message); + } + }, + error_callback: (err) => { + console.error('google sign-in error:', err); + alert('Google sign-in error: ' + (err.message || err.type || JSON.stringify(err))); } });