30 lines
828 B
TypeScript
30 lines
828 B
TypeScript
|
import fetchUserUsingAPI from "@/lib/validate-api";
|
||
|
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) {
|
||
|
const user = await fetchUserUsingAPI(req);
|
||
|
if (user != null) {
|
||
|
userId = user.id as string;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
console.log("TOKEN KEY:", userId)
|
||
|
|
||
|
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});
|
||
|
}
|
||
|
}
|