diff --git a/apps/www/src/pages/api/v0/account-linking/owned-user.ts b/apps/www/src/pages/api/v0/account-linking/owned-user.ts index a4878ec..bbafc51 100644 --- a/apps/www/src/pages/api/v0/account-linking/owned-user.ts +++ b/apps/www/src/pages/api/v0/account-linking/owned-user.ts @@ -29,39 +29,33 @@ */ import { NextApiRequest, NextApiResponse } from "next"; -import { clerkClient, getAuth } from "@clerk/nextjs/server"; +import { getAuth } from "@clerk/nextjs/server"; import { MongoClient } from "mongodb"; export default async function handler( - req: NextApiRequest, - res: NextApiResponse + req: NextApiRequest, + res: NextApiResponse, ) { - const { userId } = getAuth(req); - const { server } = req.body; + const { userId } = getAuth(req); + const { server } = req.body; - if (server == null) { - res.status(400).send({ message: "Couldn't find data" }); - return; - } + if (server == null) { + res.status(400).send({ message: "Couldn't find data" }); + return; + } - if (!userId) { - return res.status(401).json({ error: "Unauthorized" }); - } - if ( - (await (await clerkClient()).users.getUser(userId)).publicMetadata.player == - undefined - ) { - return res.status(401).json({ error: "Account not linked" }); - } - const client = new MongoClient(process.env.MONGO_DB as string); - await client.connect(); + if (!userId) { + return res.status(401).json({ error: "Unauthorized" }); + } + const client = new MongoClient(process.env.MONGO_DB as string); + await client.connect(); - const db = client.db(process.env.CUSTOM_MONGO_DB ?? "mhsf"); - const collection = db.collection("owned-servers"); + const db = client.db(process.env.CUSTOM_MONGO_DB ?? "mhsf"); + const collection = db.collection("owned-servers"); - res.send({ - result: (await collection.findOne({ server, author: userId })) != null, - }); + res.send({ + result: (await collection.findOne({ server, author: userId })) != null, + }); - client.close(); + client.close(); }