Skip to content

Commit ebc390b

Browse files
committed
Fail gracefully when Google auth is unavailable
Render the IDE instead of blocking on the OAuth client ID fetch, which left the page stuck on "Loading Google authentication..." whenever GOOGLE_AUTH_URL was unset or the auth backend was unreachable. Skip the Google login button when no auth backend is configured: mounting useGoogleLogin with an empty client ID throws and takes down the file tree panel that hosts the widget.
1 parent b684131 commit ebc390b

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

src/main.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,29 @@ initAiBuddyAccess();
1414
applyBlocklyLocale(i18n.language);
1515

1616
function Root() {
17-
const [googleClientId, setGoogleClientId] = useState<string | null>(null);
17+
const [googleClientId, setGoogleClientId] = useState<string>('');
1818
const googleAuthBackendUrl = import.meta.env.GOOGLE_AUTH_URL;
1919

2020
useEffect(() => {
21+
if (!googleAuthBackendUrl) {
22+
console.warn('GOOGLE_AUTH_URL is not set - Google sign-in is disabled.');
23+
return;
24+
}
2125
const fetchClientId = async () => {
2226
try {
2327
const response = await fetch(`${googleAuthBackendUrl}/google-auth/client-id`);
2428
if (!response.ok) {
2529
throw new Error(`Failed to fetch client ID: ${response.statusText}`);
2630
}
2731
const data = await response.json();
28-
setGoogleClientId(data.client_id);
32+
setGoogleClientId(data.client_id ?? '');
2933
} catch (error) {
34+
// The IDE stays usable without Google - only Drive sign-in is lost.
3035
console.error('Error fetching Google Client ID:', error);
31-
// Handle error appropriately, e.g., show an error message to the user
3236
}
3337
};
3438
fetchClientId();
35-
}, []);
36-
37-
if (!googleClientId) {
38-
// Optionally render a loading spinner or message
39-
return <div>Loading Google authentication...</div>;
40-
}
39+
}, [googleAuthBackendUrl]);
4140

4241
return (
4342
<StrictMode>

src/widgets/login.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ function mapDriveAboutUser(data: DriveAboutResponse): UserProfile | null {
5454
};
5555
}
5656

57-
function Login({ logoutCallback, onSuccess }: LoginProps) {
57+
/** Without an auth backend there is no OAuth client ID to sign in with. */
58+
const isGoogleAuthConfigured = Boolean(import.meta.env.GOOGLE_AUTH_URL);
59+
60+
function GoogleLoginButton({ logoutCallback, onSuccess }: LoginProps) {
5861
const { t } = useTranslation();
5962
const [isLogin, setIsLogin] = useState<boolean>(false);
6063
const [isSigningIn, setIsSigningIn] = useState<boolean>(false);
@@ -284,4 +287,13 @@ function Login({ logoutCallback, onSuccess }: LoginProps) {
284287
);
285288
}
286289

290+
/**
291+
* Google sign-in button. When Google auth is not configured the button is left
292+
* out entirely - useGoogleLogin throws on an empty client ID, which would take
293+
* down the file tree that hosts this widget.
294+
*/
295+
function Login(props: LoginProps) {
296+
return isGoogleAuthConfigured ? <GoogleLoginButton {...props} /> : null;
297+
}
298+
287299
export default Login;

0 commit comments

Comments
 (0)