Files
sim/apps/sim/app/api/auth/accounts/route.ts
Vikhyath Mondreti 3b9f0f9ce2 feat(error-notifications): workspace-level configuration of slack, email, webhook notifications for workflow execution (#2157)
* feat(notification): slack, email, webhook notifications from logs

* retain search params for filters to link in notification

* add alerting rules

* update selector

* fix lint

* add limits on num of emails and notification triggers per workspace

* address greptile comments

* add search to combobox

* move notifications to react query

* fix lint

* fix email formatting

* add more alert types

* fix imports

* fix test route

* use emcn componentfor modal

* refactor: consolidate notification config fields into jsonb objects

* regen migration

* fix delete notif modal ui

* make them multiselect dropdowns

* update tag styling

* combobox font size with multiselect tags'
2025-12-04 18:29:22 -08:00

41 lines
1.2 KiB
TypeScript

import { db } from '@sim/db'
import { account } from '@sim/db/schema'
import { and, eq } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { getSession } from '@/lib/auth'
import { createLogger } from '@/lib/logs/console/logger'
const logger = createLogger('AuthAccountsAPI')
export async function GET(request: NextRequest) {
try {
const session = await getSession()
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const { searchParams } = new URL(request.url)
const provider = searchParams.get('provider')
const whereConditions = [eq(account.userId, session.user.id)]
if (provider) {
whereConditions.push(eq(account.providerId, provider))
}
const accounts = await db
.select({
id: account.id,
accountId: account.accountId,
providerId: account.providerId,
})
.from(account)
.where(and(...whereConditions))
return NextResponse.json({ accounts })
} catch (error) {
logger.error('Failed to fetch accounts', { error })
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
}
}