Skip to content

Commit af7cc43

Browse files
committed
fix(files): extract userId const to satisfy TypeScript narrowing in async callback
1 parent c69787c commit af7cc43

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

  • apps/sim/app/api/files/export/[id]

apps/sim/app/api/files/export/[id]/route.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,17 @@ export const GET = withRouteHandler(
5555
if (!authResult.success || !authResult.userId) {
5656
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
5757
}
58+
const userId = authResult.userId
5859

5960
const record = await getFileMetadataById(id)
6061
if (!record) {
6162
logger.warn('File not found by ID', { id })
6263
return NextResponse.json({ error: 'Not found' }, { status: 404 })
6364
}
6465

65-
const hasAccess = await verifyFileAccess(record.key, authResult.userId)
66+
const hasAccess = await verifyFileAccess(record.key, userId)
6667
if (!hasAccess) {
67-
logger.warn('Unauthorized file export attempt', { id, userId: authResult.userId })
68+
logger.warn('Unauthorized file export attempt', { id, userId })
6869
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
6970
}
7071

@@ -91,7 +92,7 @@ export const GET = withRouteHandler(
9192
imageIds.map(async (imageId) => {
9293
const imgRecord = await getFileMetadataById(imageId)
9394
if (!imgRecord) return null
94-
const imgHasAccess = await verifyFileAccess(imgRecord.key, authResult.userId)
95+
const imgHasAccess = await verifyFileAccess(imgRecord.key, userId)
9596
if (!imgHasAccess) return null
9697
const imgBuffer = await downloadFile({
9798
key: imgRecord.key,

0 commit comments

Comments
 (0)