fix(google-chat): add OAuth provider registration to auth.ts

This commit is contained in:
Waleed Latif
2026-02-25 13:53:59 -08:00
parent 30cb108b30
commit f5c8c47fcf

View File

@@ -486,6 +486,7 @@ export const auth = betterAuth({
'google-forms',
'google-vault',
'google-groups',
'google-chat',
'vertex-ai',
'github-repo',
'microsoft-dataverse',
@@ -1150,6 +1151,47 @@ export const auth = betterAuth({
},
},
{
providerId: 'google-chat',
clientId: env.GOOGLE_CLIENT_ID as string,
clientSecret: env.GOOGLE_CLIENT_SECRET as string,
discoveryUrl: 'https://accounts.google.com/.well-known/openid-configuration',
accessType: 'offline',
scopes: [
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/chat.spaces.readonly',
'https://www.googleapis.com/auth/chat.messages.create',
],
prompt: 'consent',
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/google-chat`,
getUserInfo: async (tokens) => {
try {
const response = await fetch('https://openidconnect.googleapis.com/v1/userinfo', {
headers: { Authorization: `Bearer ${tokens.accessToken}` },
})
if (!response.ok) {
logger.error('Failed to fetch Google user info', { status: response.status })
throw new Error(`Failed to fetch Google user info: ${response.statusText}`)
}
const profile = await response.json()
const now = new Date()
return {
id: `${profile.sub}-${crypto.randomUUID()}`,
name: profile.name || 'Google User',
email: profile.email,
image: profile.picture || undefined,
emailVerified: profile.email_verified || false,
createdAt: now,
updatedAt: now,
}
} catch (error) {
logger.error('Error in Google getUserInfo', { error })
throw error
}
},
},
{
providerId: 'vertex-ai',
clientId: env.GOOGLE_CLIENT_ID as string,