-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmiddleware.ts
More file actions
22 lines (18 loc) · 831 Bytes
/
middleware.ts
File metadata and controls
22 lines (18 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest) {
// Only run on /vectorset route
if (request.nextUrl.pathname === '/vectorset') {
const connectionId = request.nextUrl.searchParams.get('cid')
// If no connection ID is present, redirect to home
if (!connectionId) {
return NextResponse.redirect(new URL('/console', request.url))
}
// Add validation for connection ID format (assuming UUID format)
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
if (!uuidRegex.test(connectionId)) {
return NextResponse.redirect(new URL('/console', request.url))
}
}
return NextResponse.next()
}