@@ -2,7 +2,7 @@ import { createLogger } from '@sim/logger'
22import { toError } from '@sim/utils/errors'
33import { headers } from 'next/headers'
44import { type NextRequest , NextResponse } from 'next/server'
5- import { auth } from '@/lib/auth'
5+ import { auth , getSession } from '@/lib/auth'
66import { isAuthDisabled } from '@/lib/core/config/env-flags'
77import { enforceIpRateLimit } from '@/lib/core/rate-limiter'
88import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
@@ -21,6 +21,17 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
2121 } )
2222 if ( rateLimited ) return rateLimited
2323
24+ // Gate socket-token minting through the enforcing getSession chokepoint so a
25+ // member blocked by the org IP allowlist can't obtain a socket token in the
26+ // first place — making the app the primary socket gate (same cache and
27+ // ~60s propagation as every other surface). `generateOneTimeToken` uses
28+ // Better Auth's internal session middleware, which does not run the
29+ // customSession network-policy check, so this explicit call is required.
30+ const session = await getSession ( )
31+ if ( ! session ?. user ?. id ) {
32+ return NextResponse . json ( { error : 'Authentication required' } , { status : 401 } )
33+ }
34+
2435 try {
2536 const hdrs = await headers ( )
2637 const response = await auth . api . generateOneTimeToken ( {
0 commit comments