(request: NextRequest)
| 85 | } |
| 86 | |
| 87 | export async function GET(request: NextRequest) { |
| 88 | let userId: string | undefined |
| 89 | |
| 90 | // First, try Bearer token authentication (for CLI clients) |
| 91 | const apiKey = extractApiKeyFromHeader(request) |
| 92 | if (apiKey) { |
| 93 | const userIdFromToken = await getUserIdFromSessionToken(apiKey) |
| 94 | if (userIdFromToken) { |
| 95 | userId = userIdFromToken |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // Fall back to NextAuth session authentication (for web clients) |
| 100 | if (!userId) { |
| 101 | const session = await getServerSession(authOptions) |
| 102 | userId = session?.user?.id |
| 103 | } |
| 104 | |
| 105 | if (!userId) { |
| 106 | return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) |
| 107 | } |
| 108 | |
| 109 | const user = await db.query.user.findFirst({ |
| 110 | where: eq(schema.user.id, userId), |
| 111 | columns: { fallback_to_a_la_carte: true }, |
| 112 | }) |
| 113 | |
| 114 | if (!user) { |
| 115 | return NextResponse.json({ error: 'User not found' }, { status: 404 }) |
| 116 | } |
| 117 | |
| 118 | return NextResponse.json({ |
| 119 | fallbackToALaCarte: user.fallback_to_a_la_carte, |
| 120 | }) |
| 121 | } |
nothing calls this directly
no test coverage detected