fix(server-linking): remove useless backend condition

This commit is contained in:
dvelo 2025-03-02 15:27:07 -06:00
parent 1a6e50868c
commit e729895729

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