MCPcopy Create free account
hub / github.com/anus-dev/ANUS / fetchAndCacheUserInfo

Function fetchAndCacheUserInfo

packages/core/src/code_assist/oauth2.ts:405–437  ·  view source on GitHub ↗
(client: OAuth2Client)

Source from the content-addressed store, hash-verified

403}
404
405async function fetchAndCacheUserInfo(client: OAuth2Client): Promise<void> {
406 try {
407 const { token } = await client.getAccessToken();
408 if (!token) {
409 return;
410 }
411
412 const response = await fetch(
413 'https://www.googleapis.com/oauth2/v2/userinfo',
414 {
415 headers: {
416 Authorization: `Bearer ${token}`,
417 },
418 },
419 );
420
421 if (!response.ok) {
422 console.error(
423 'Failed to fetch user info:',
424 response.status,
425 response.statusText,
426 );
427 return;
428 }
429
430 const userInfo = await response.json();
431 if (userInfo.email) {
432 await cacheGoogleAccount(userInfo.email);
433 }
434 } catch (error) {
435 console.error('Error retrieving user info:', error);
436 }
437}
438
439// Helper to ensure test isolation
440export function resetOauthClientForTesting() {

Callers 2

initOauthClientFunction · 0.85
authWithWebFunction · 0.85

Calls 1

cacheGoogleAccountFunction · 0.85

Tested by

no test coverage detected