11import { db } from '@sim/db'
2- import { workflow , workspace } from '@sim/db/schema'
2+ import { session , workflow , workspace } from '@sim/db/schema'
33import { eq } from 'drizzle-orm'
44import { type NextRequest , NextResponse } from 'next/server'
55import { z } from 'zod'
6- import { getSession } from '@/lib/auth'
6+ import { checkHybridAuth } from '@/lib/auth/hybrid '
77import { createLogger } from '@/lib/logs/console/logger'
88import { generateRequestId } from '@/lib/utils'
99import { 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
8484export 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