add cloudflare context to admin

This commit is contained in:
2025-12-18 00:04:48 -03:00
parent be1ae656d3
commit 8c7c3034d4
16 changed files with 67 additions and 50 deletions

View File

@@ -1,7 +1,6 @@
import type { Route } from './+types/route'
import type { User } from '@repo/auth/auth'
import { userContext } from '@repo/auth/context'
import { userContext, cloudflareContext } from '@repo/auth/context'
import { authMiddleware } from '@repo/auth/middleware/auth'
export const middleware: Route.MiddlewareFunction[] = [authMiddleware]
@@ -13,8 +12,9 @@ async function proxy({
context
}: Route.ActionArgs): Promise<Response> {
const pathname = new URL(request.url).pathname.replace(/^\/~\/api\//, '')
const user = context.get(userContext) as User
const url = new URL(pathname, context.cloudflare.env.API_URL)
const cloudflare = context.get(cloudflareContext)
const user = context.get(userContext)!
const url = new URL(pathname, cloudflare.env.API_URL)
const headers = new Headers(request.headers)
headers.set('Authorization', `Bearer ${user.accessToken}`)