2023-12-30 05:56:40 -05:00
|
|
|
import { db } from "@/lib/db"
|
|
|
|
import { NextResponse } from "next/server";
|
2024-06-24 18:16:55 -04:00
|
|
|
import fetchUserWithImpersonation from "@/lib/fetch-user-impersonation";
|
2023-12-30 05:56:40 -05:00
|
|
|
|
|
|
|
export async function GET(req: Request) {
|
|
|
|
try {
|
2024-06-24 18:16:55 -04:00
|
|
|
const user = await fetchUserWithImpersonation(req)
|
|
|
|
if (!user) {
|
2024-08-25 17:35:46 -04:00
|
|
|
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
|
2023-12-30 05:56:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const tokens = await db.apiKey.findMany({
|
|
|
|
where: {
|
2024-06-24 18:16:55 -04:00
|
|
|
userId: user.id
|
2023-12-30 05:56:40 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return NextResponse.json(tokens);
|
|
|
|
} catch (error) {
|
|
|
|
console.log("[TOKENS/GET]", error);
|
2024-08-25 17:35:46 -04:00
|
|
|
return NextResponse.json({ message: 'Something went wrong', error: error, value: null }, { status: 500 })
|
2023-12-30 05:56:40 -05:00
|
|
|
}
|
|
|
|
}
|