Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .claude/settings.local.json

This file was deleted.

19 changes: 16 additions & 3 deletions packages/api/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { auth } from "@query/auth";
import { db } from "@query/db";
import type { FetchCreateContextFnOptions } from "@trpc/server/adapters/fetch";
import { cache } from "./middleware/cache";

// Lazy import auth to avoid module resolution issues in standalone builds
let authModule: { auth: () => Promise<any> } | null = null;

async function getAuth() {
if (authModule === null) {
try {
authModule = await import("@query/auth");
} catch (error) {
console.warn("Auth module not available:", error);
authModule = { auth: async () => null };
}
}
return authModule.auth;
}

export async function createContext(
opts?: FetchCreateContextFnOptions & { clientIp?: string; req?: Request }
) {
Expand All @@ -14,8 +28,7 @@ export async function createContext(
// Only attempt auth if database is available
if (db) {
try {
// Pass the request to auth() if available, which helps in some Next.js environments
// casting simplified as usually auth() picks up headers context automatically in Server Components/Actions
const auth = await getAuth();
session = await auth();
} catch (error) {
console.warn("Failed to fetch auth session:", error);
Expand Down