From 13bfa41489899c19db6e31fcd09036cd5094ef19 Mon Sep 17 00:00:00 2001 From: wass08 Date: Wed, 11 Feb 2026 16:40:24 +0900 Subject: [PATCH] fix build env --- apps/editor/app/api/auth/[...all]/route.ts | 22 +++++++++++++++++++++- packages/auth/src/server.ts | 20 ++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/apps/editor/app/api/auth/[...all]/route.ts b/apps/editor/app/api/auth/[...all]/route.ts index 4dbec88a..4cc0fb0e 100644 --- a/apps/editor/app/api/auth/[...all]/route.ts +++ b/apps/editor/app/api/auth/[...all]/route.ts @@ -5,5 +5,25 @@ import { auth } from '@pascal-app/auth/server' import { toNextJsHandler } from 'better-auth/next-js' +import type { NextRequest } from 'next/server' -export const { GET, POST } = toNextJsHandler(auth) +// Lazy initialization of the handler +let handler: ReturnType | null = null + +function getHandler() { + if (!handler) { + handler = toNextJsHandler(auth) + } + return handler +} + +// Export route handlers that initialize lazily +export async function GET(request: NextRequest) { + const { GET: getHandler } = getHandler() + return getHandler(request) +} + +export async function POST(request: NextRequest) { + const { POST: postHandler } = getHandler() + return postHandler(request) +} diff --git a/packages/auth/src/server.ts b/packages/auth/src/server.ts index 4a84ec9e..5071ea96 100644 --- a/packages/auth/src/server.ts +++ b/packages/auth/src/server.ts @@ -104,6 +104,22 @@ export const auth = new Proxy({} as ReturnType, { /** * Type helpers for better-auth session + * These are generic types that should match Better Auth's session structure */ -export type Session = typeof auth.$Infer.Session.session -export type User = typeof auth.$Infer.Session.user +export type Session = { + id: string + userId: string + activePropertyId?: string | null + expiresAt: Date + createdAt: Date + updatedAt: Date +} + +export type User = { + id: string + email: string + emailVerified: boolean + name: string + createdAt: Date + updatedAt: Date +}