Share
diff --git a/apps/www/src/components/feat/server-page/server-provider.tsx b/apps/www/src/components/feat/server-page/server-provider.tsx
index 7b72db2..ee9bcff 100644
--- a/apps/www/src/components/feat/server-page/server-provider.tsx
+++ b/apps/www/src/components/feat/server-page/server-provider.tsx
@@ -72,7 +72,7 @@ export function ServerProvider({ serverId }: { serverId: string }) {
) : (
-
+
= (await mh.json()).servers;
+ if ((await users.findOne({ userId })) === null) {
+ return res.status(401).json({ error: "Account not linked" });
+ }
- servers.forEach(async (c, i) => {
- if (c.name === server) {
- const MCUsername = (await (await clerkClient()).users.getUser(userId))
- .publicMetadata.player;
+ const minecraftUsername = (await users.findOne({ userId }))?.player;
- if (MCUsername === c.author) {
- await collection.insertOne({ server, author: userId });
+ if ((await collection.findOne({ server })) === null) {
+ const mh = await fetch(
+ process.env.MHSF_BACKEND_API_LOCATION ??
+ "https://api.minehut.com/servers",
+ {
+ headers: {
+ accept: "*/*",
+ "accept-language": Math.random().toString(),
+ priority: "u=1, i",
+ "sec-ch-ua": '"Not/A)Brand";v="8", "Chromium";v="126"',
+ "sec-ch-ua-mobile": "?0",
+ "sec-ch-ua-platform": '"macOS"',
+ "sec-fetch-dest": "empty",
+ "sec-fetch-mode": "cors",
+ "sec-fetch-site": "cross-site",
+ Referer: "http://localhost:3000/",
+ "Referrer-Policy": "strict-origin-when-cross-origin",
+ Authentication: `MHSF-Backend-Server ${process.env.MHSF_BACKEND_API_LOCATION ? process.env.MHSF_BACKEND_SECRET : "Sorry Minehut Devs."}`,
+ },
+ body: null,
+ method: "GET",
+ },
+ );
+ const servers: Array = (await mh.json()).servers;
+ const serverObj = servers.find((c) => c.staticInfo._id === server);
- // Close the database, but don't close this
- // serverless instance until it happens
- waitUntil(client.close());
+ if (serverObj === undefined)
+ return res
+ .status(400)
+ .send({ message: "The server needs to be online." });
- res.send({ message: "Successfully owned server!" });
- } else {
- // Close the database, but don't close this
- // serverless instance until it happens
- waitUntil(client.close());
+ if (minecraftUsername === serverObj.author) {
+ await collection.insertOne({ server, author: userId });
- res
- .status(400)
- .send({ message: "The linked account doesn't own the server." });
- }
- }
- if (i === servers.length) {
- // Close the database, but don't close this
- // serverless instance until it happens
- waitUntil(client.close());
+ // Close the database, but don't close this
+ // serverless instance until it happens
+ waitUntil(client.close());
- res.status(400).send({ message: "The server needs to be online." });
- }
- });
- } else {
- // Close the database, but don't close this
- // serverless instance until it happens
- waitUntil(client.close());
+ res.send({ message: "Successfully owned server!" });
+ } else {
+ res
+ .status(400)
+ .send({ message: "The linked account doesn't own the server." });
+ }
+ } else {
+ // Close the database, but don't close this
+ // serverless instance until it happens
+ waitUntil(client.close());
- res.status(400).send({ message: "This server has already been owned." });
- }
+ res.status(400).send({ message: "This server has already been owned." });
+ }
}
diff --git a/apps/www/src/pages/api/v1/user/claimed-user.ts b/apps/www/src/pages/api/v1/user/claimed-user.ts
new file mode 100644
index 0000000..ba024f5
--- /dev/null
+++ b/apps/www/src/pages/api/v1/user/claimed-user.ts
@@ -0,0 +1,52 @@
+/*
+ * MHSF, Minehut Server List
+ * All external content is rather licensed under the ECA Agreement
+ * located here: https://mhsf.app/docs/legal/external-content-agreement
+ *
+ * All code under MHSF is licensed under the MIT License
+ * by open source contributors
+ *
+ * Copyright (c) 2025 dvelo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+import type { NextApiRequest, NextApiResponse } from "next";
+import { getAuth, clerkClient } from "@clerk/nextjs/server";
+import { MongoClient } from "mongodb";
+import { waitUntil } from "@vercel/functions";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ const { userId } = getAuth(req);
+
+ 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 users = db.collection("claimed-users");
+
+ return res.send((await users.findOne({ userId })) ?? {player: null});
+}