Skip to content

Commit 9e8b0b3

Browse files
committed
feat(api): Use hybrid auth for workflows list route
1 parent 2ee27f9 commit 9e8b0b3

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

apps/sim/app/api/workflows/route.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { db } from '@sim/db'
2-
import { workflow, workspace } from '@sim/db/schema'
2+
import { session, workflow, workspace } from '@sim/db/schema'
33
import { eq } from 'drizzle-orm'
44
import { type NextRequest, NextResponse } from 'next/server'
55
import { z } from 'zod'
6-
import { getSession } from '@/lib/auth'
6+
import { checkHybridAuth } from '@/lib/auth/hybrid'
77
import { createLogger } from '@/lib/logs/console/logger'
88
import { generateRequestId } from '@/lib/utils'
99
import { verifyWorkspaceMembership } from './utils'
@@ -19,20 +19,20 @@ const CreateWorkflowSchema = z.object({
1919
})
2020

2121
// GET /api/workflows - Get workflows for user (optionally filtered by workspaceId)
22-
export async function GET(request: Request) {
22+
export async function GET(request: NextRequest) {
2323
const requestId = generateRequestId()
2424
const startTime = Date.now()
2525
const url = new URL(request.url)
2626
const workspaceId = url.searchParams.get('workspaceId')
2727

2828
try {
29-
const session = await getSession()
30-
if (!session?.user?.id) {
29+
const authResult = await checkHybridAuth(request)
30+
if (!authResult.success || !authResult.userId) {
3131
logger.warn(`[${requestId}] Unauthorized workflow access attempt`)
3232
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
3333
}
3434

35-
const userId = session.user.id
35+
const userId = authResult.userId
3636

3737
if (workspaceId) {
3838
const workspaceExists = await db
@@ -83,9 +83,9 @@ export async function GET(request: Request) {
8383
// POST /api/workflows - Create a new workflow
8484
export async function POST(req: NextRequest) {
8585
const requestId = generateRequestId()
86-
const session = await getSession()
86+
const authResult = await checkHybridAuth(req)
8787

88-
if (!session?.user?.id) {
88+
if (!authResult.success || !authResult.userId) {
8989
logger.warn(`[${requestId}] Unauthorized workflow creation attempt`)
9090
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
9191
}
@@ -97,11 +97,11 @@ export async function POST(req: NextRequest) {
9797
const workflowId = crypto.randomUUID()
9898
const now = new Date()
9999

100-
logger.info(`[${requestId}] Creating workflow ${workflowId} for user ${session.user.id}`)
100+
logger.info(`[${requestId}] Creating workflow ${workflowId} for user ${authResult.userId}`)
101101

102102
await db.insert(workflow).values({
103103
id: workflowId,
104-
userId: session.user.id,
104+
userId: authResult.userId,
105105
workspaceId: workspaceId || null,
106106
folderId: folderId || null,
107107
name,

0 commit comments

Comments
 (0)