51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { db } from "@/lib/db"
|
|
import fetchUserWithImpersonation from "@/lib/fetch-user-impersonation";
|
|
import { NextResponse } from "next/server";
|
|
|
|
export async function GET(req: Request, { params } : { params: { id: string } }) {
|
|
try {
|
|
const user = await fetchUserWithImpersonation(req)
|
|
if (!user) {
|
|
return new NextResponse("Unauthorized", { status: 401 });
|
|
}
|
|
|
|
let id = req.headers?.get('x-api-key')
|
|
if (id == null) {
|
|
return NextResponse.json(null);
|
|
}
|
|
|
|
const tokens = await db.apiKey.findFirst({
|
|
where: {
|
|
id: id
|
|
}
|
|
});
|
|
|
|
return NextResponse.json(tokens);
|
|
} catch (error) {
|
|
console.log("[TOKEN/GET]", error);
|
|
return new NextResponse("Internal Error", { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function DELETE(req: Request, { params } : { params: { id: string } }) {
|
|
try {
|
|
const user = await fetchUserWithImpersonation(req)
|
|
|
|
if (!user) {
|
|
return new NextResponse("Unauthorized", { status: 401 });
|
|
}
|
|
|
|
const { id } = params
|
|
const token = await db.apiKey.delete({
|
|
where: {
|
|
id,
|
|
userId: user?.id
|
|
}
|
|
});
|
|
|
|
return NextResponse.json(token);
|
|
} catch (error) {
|
|
console.log("[TOKEN/DELETE]", error);
|
|
return new NextResponse("Internal Error", { status: 500 });
|
|
}
|
|
} |