mirror of
https://github.com/DeveloLongScript/MHSF.git
synced 2026-05-07 13:05:00 -05:00
fix(server-linking): remove useless backend condition
This commit is contained in:
parent
1a6e50868c
commit
e729895729
@ -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();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user