diff --git a/apps/mail/actions/brain.ts b/apps/mail/actions/brain.ts index 491668bac2..d4aab9b38f 100644 --- a/apps/mail/actions/brain.ts +++ b/apps/mail/actions/brain.ts @@ -1,14 +1,22 @@ 'use server'; +import { getActiveConnection } from './utils'; import axios from 'axios'; export const EnableBrain = async ({ connection, }: { - connection: { id: string; providerId: string }; + connection?: { id: string; providerId: string } | null; }) => { if (!process.env.BRAIN_URL) { return false; } + if (!connection) { + connection = await getActiveConnection(); + } + + if (!connection?.id) { + return false; + } return await axios .put(process.env.BRAIN_URL + `/subscribe/${connection.providerId}`, { diff --git a/apps/mail/app/api/driver/google.ts b/apps/mail/app/api/driver/google.ts index 8af30acec5..d6e1d0f96c 100644 --- a/apps/mail/app/api/driver/google.ts +++ b/apps/mail/app/api/driver/google.ts @@ -562,11 +562,16 @@ export const driver = async (config: IConfig): Promise => { getUserInfo: (tokens: IConfig['auth']) => { return withErrorHandler( 'getUserInfo', - () => { + async () => { auth.setCredentials({ ...tokens, scope: getScope() }); - return google + const res = await google .people({ version: 'v1', auth }) .people.get({ resourceName: 'people/me', personFields: 'names,photos,emailAddresses' }); + return { + address: res.data.emailAddresses?.[0]?.value ?? '', + name: res.data.names?.[0]?.displayName ?? '', + photo: res.data.photos?.[0]?.url ?? '', + }; }, { tokens }, ); diff --git a/apps/mail/components/ui/nav-user.tsx b/apps/mail/components/ui/nav-user.tsx index 99ada537b7..b18b9602eb 100644 --- a/apps/mail/components/ui/nav-user.tsx +++ b/apps/mail/components/ui/nav-user.tsx @@ -1,6 +1,7 @@ 'use client'; import { + BrainCircuitIcon, ChevronDown, HelpCircle, LogIn, @@ -18,19 +19,20 @@ import { DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { SidebarMenu, SidebarMenuItem, SidebarMenuButton } from '@/components/ui/sidebar'; +import { useCallback, useEffect, useMemo, useState } from 'react'; +import { usePathname, useSearchParams } from 'next/navigation'; import { useConnections } from '@/hooks/use-connections'; -import { useRouter } from 'next/navigation'; import { signOut, useSession } from '@/lib/auth-client'; import { AddConnectionDialog } from '../connection/add'; import { putConnection } from '@/actions/connections'; -import { useCallback, useEffect, useMemo, useState } from 'react'; +import { dexieStorageProvider } from '@/lib/idb'; import { SunIcon } from '../icons/animated/sun'; +import { EnableBrain } from '@/actions/brain'; +import { useRouter } from 'next/navigation'; import { useTranslations } from 'next-intl'; import { type IConnection } from '@/types'; import { useTheme } from 'next-themes'; import { toast } from 'sonner'; -import { dexieStorageProvider } from '@/lib/idb'; -import { usePathname, useSearchParams } from 'next/navigation'; import Link from 'next/link'; export function NavUser() { @@ -62,6 +64,12 @@ export function NavUser() { toast.success('Cache cleared successfully'); }, []); + const handleEnableBrain = useCallback(async () => { + // This takes too long, not waiting + const enabled = await EnableBrain({}); + if (enabled) toast.success('Brain enabled successfully'); + }, []); + const activeAccount = useMemo(() => { if (!session) return null; return connections?.find((connection) => connection.id === session?.connectionId); @@ -95,11 +103,14 @@ export function NavUser() { }; const handleLogout = async () => { - toast.promise(signOut().then(() => router.push('/login')), { - loading: 'Signing out...', - success: () => 'Signed out successfully!', - error: 'Error signing out', - }); + toast.promise( + signOut().then(() => router.push('/login')), + { + loading: 'Signing out...', + success: () => 'Signed out successfully!', + error: 'Error signing out', + }, + ); }; return ( @@ -266,7 +277,6 @@ export function NavUser() {

{t('common.actions.logout')}

- ) : ( <> @@ -291,15 +301,19 @@ export function NavUser() { -

- Debug -

+

Debug

Clear Local Cache

+ +
+ +

Enable Brain

+
+
)}