mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix(api-v1): strengthen middleware type safety and remove redundant import
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { auth } from "@/lib/auth/auth";
|
import { auth } from "@/lib/auth/auth";
|
||||||
import { db } from "@/db";
|
|
||||||
import * as drizzleDb from "@/db";
|
import * as drizzleDb from "@/db";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { logger } from "@/lib/logger";
|
import { logger } from "@/lib/logger";
|
||||||
@@ -15,7 +14,7 @@ export type ApiKeyContext = {
|
|||||||
type ApiKeyHandler = (
|
type ApiKeyHandler = (
|
||||||
req: Request,
|
req: Request,
|
||||||
ctx: ApiKeyContext,
|
ctx: ApiKeyContext,
|
||||||
params: Record<string, string>
|
params?: Record<string, string>
|
||||||
) => Promise<Response>;
|
) => Promise<Response>;
|
||||||
|
|
||||||
export function withApiKey(handler: ApiKeyHandler) {
|
export function withApiKey(handler: ApiKeyHandler) {
|
||||||
@@ -44,7 +43,11 @@ export function withApiKey(handler: ApiKeyHandler) {
|
|||||||
|
|
||||||
const userId = result.key.referenceId as string;
|
const userId = result.key.referenceId as string;
|
||||||
|
|
||||||
const memberships = await db.query.member.findMany({
|
if (!userId) {
|
||||||
|
return NextResponse.json({ error: "Invalid or expired API key" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const memberships = await drizzleDb.db.query.member.findMany({
|
||||||
where: eq(drizzleDb.schemas.member.userId, userId),
|
where: eq(drizzleDb.schemas.member.userId, userId),
|
||||||
columns: { organizationId: true },
|
columns: { organizationId: true },
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user