2024-01-04 16:57:32 -05:00
|
|
|
import fetchUser from "@/lib/fetch-user";
|
2023-12-30 05:56:40 -05:00
|
|
|
import { db } from "@/lib/db"
|
|
|
|
import { NextResponse } from "next/server";
|
|
|
|
|
|
|
|
export async function GET(req: Request) {
|
|
|
|
try {
|
|
|
|
const { searchParams } = new URL(req.url)
|
|
|
|
let userId = searchParams.get('userId')
|
|
|
|
|
|
|
|
if (userId == null) {
|
2024-01-04 16:57:32 -05:00
|
|
|
const user = await fetchUser(req);
|
2023-12-30 05:56:40 -05:00
|
|
|
if (user != null) {
|
|
|
|
userId = user.id as string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const tokens = await db.apiKey.findMany({
|
|
|
|
where: {
|
|
|
|
userId: userId as string
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return NextResponse.json(tokens);
|
|
|
|
} catch (error) {
|
|
|
|
console.log("[TOKENS/GET]", error);
|
|
|
|
return new NextResponse("Internal Error", { status: 500});
|
|
|
|
}
|
|
|
|
}
|