Add error handling to Google sign-in flow
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -97,15 +97,27 @@ export async function auth() {
|
|||||||
google.accounts.id.initialize({
|
google.accounts.id.initialize({
|
||||||
client_id: CLIENT_ID,
|
client_id: CLIENT_ID,
|
||||||
callback: async (response) => {
|
callback: async (response) => {
|
||||||
const res = await fetch('/auth/google/callback', {
|
try {
|
||||||
method: 'POST',
|
const res = await fetch('/auth/google/callback', {
|
||||||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
method: 'POST',
|
||||||
body: 'credential=' + encodeURIComponent(response.credential)
|
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||||||
});
|
body: 'credential=' + encodeURIComponent(response.credential)
|
||||||
const profile = await res.json();
|
});
|
||||||
setProfile(profile);
|
if (!res.ok) {
|
||||||
signin.style.display = 'none';
|
throw new Error(`server returned ${res.status}: ${await res.text()}`);
|
||||||
resolve(profile);
|
}
|
||||||
|
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)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user