From af5e138391708c14ee2729d1bb8deea7592e6655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emrik=20=C3=96stling?= Date: Mon, 4 Nov 2024 23:00:57 +0100 Subject: [PATCH] add some more games --- README.md | 2 +- app/api/auth/[...nextauth]/route.ts | 13 +- app/api/minecraft/actions.ts | 30 + app/api/minecraft/route.ts | 0 app/components/copy-text.tsx | 31 + app/components/logout-button.tsx | 2 +- app/components/minecraft-login.tsx | 46 + app/games/page.tsx | 65 +- app/lib/auth.ts | 18 + app/page.tsx | 22 + next.config.mjs | 1 - package-lock.json | 1347 ++++++++++++++++++++++++--- package.json | 11 +- public/games/factorio.png | Bin 0 -> 881411 bytes public/games/valheim.png | Bin 0 -> 543830 bytes tsconfig.json | 6 +- 16 files changed, 1436 insertions(+), 158 deletions(-) create mode 100644 app/api/minecraft/actions.ts create mode 100644 app/api/minecraft/route.ts create mode 100644 app/components/copy-text.tsx create mode 100644 app/components/minecraft-login.tsx create mode 100644 app/lib/auth.ts create mode 100644 public/games/factorio.png create mode 100644 public/games/valheim.png diff --git a/README.md b/README.md index 8b5bbcf..91fdc68 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # G.U.D. Gaming -Work in progress. \ No newline at end of file +Work in progress. diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index eae675c..dea2d8c 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -1,20 +1,21 @@ import NextAuth from "next-auth"; +import type { NextAuthOptions } from "next-auth"; import BoxyHQ from "next-auth/providers/boxyhq-saml"; -const samlLoginUrl = process.env.AUTH_BOXYHQ_SAML_ISSUER; - // For more information on each option (and a full list of options) go to // https://next-auth.js.org/configuration/options -const handler = NextAuth({ - // https://next-auth.js.org/configuration/providers/oauth + +export const authOptions: NextAuthOptions = { providers: [ BoxyHQ({ authorization: { params: { scope: "" } }, - issuer: samlLoginUrl, + issuer: process.env.AUTH_BOXYHQ_SAML_ISSUER, clientId: process.env.AUTH_BOXYHQ_SAML_ID || "dummy", clientSecret: process.env.AUTH_BOXYHQ_SAML_SECRET || "dummy", }), ], -}); +}; + +const handler = NextAuth(authOptions); export { handler as GET, handler as POST }; diff --git a/app/api/minecraft/actions.ts b/app/api/minecraft/actions.ts new file mode 100644 index 0000000..973b56f --- /dev/null +++ b/app/api/minecraft/actions.ts @@ -0,0 +1,30 @@ +"use server"; + +interface MojangResponse { + id: string; + name: string; +} + +export async function register(prevState: any, formData: FormData) { + const username = formData.get("username").toString().toLowerCase(); + + if (!username) { + return { message: "Username is required" }; + } + + const response = await fetch( + `https://api.mojang.com/users/profiles/minecraft/${username}`, + ); + + if (response.status === 404 || !response.ok) { + return { message: "Username not found" }; + } + + const uuid = ((await response.json()) as MojangResponse).id; + + if (!uuid) { + return { message: "UUID not found" }; + } + + return { message: "Saved" }; +} diff --git a/app/api/minecraft/route.ts b/app/api/minecraft/route.ts new file mode 100644 index 0000000..e69de29 diff --git a/app/components/copy-text.tsx b/app/components/copy-text.tsx new file mode 100644 index 0000000..657e471 --- /dev/null +++ b/app/components/copy-text.tsx @@ -0,0 +1,31 @@ +"use client"; + +export function CopyText({ text }: { text: string }) { + return ( + + ); +} diff --git a/app/components/logout-button.tsx b/app/components/logout-button.tsx index df5e944..958bd41 100644 --- a/app/components/logout-button.tsx +++ b/app/components/logout-button.tsx @@ -6,7 +6,7 @@ export function LogoutButton() { return ( + + ); +} diff --git a/app/games/page.tsx b/app/games/page.tsx index 16d8dfb..f3e2532 100644 --- a/app/games/page.tsx +++ b/app/games/page.tsx @@ -1,8 +1,18 @@ +import { auth } from "@/app/lib/auth"; import Link from "next/link"; +import { redirect } from "next/navigation"; +import { CopyText } from "../components/copy-text"; import { LogoutButton } from "../components/logout-button"; +import { MinecraftLogin } from "../components/minecraft-login"; + +export default async function Page() { + const session = await auth(); + + if (!session) { + redirect("/"); + } -export default function Page() { return ( <>
-

Games

+

Games

+
-
+
+

+ Welcome {session?.user?.name}! +

Find the games you want to play in the list below. Some games needs your playername for whitelist. You can always come back to this page by login in again.

-