From 58713f216d340f7b334128ff71b701cd43fadcf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emrik=20=C3=96stling?= Date: Mon, 18 Nov 2024 22:46:03 +0100 Subject: [PATCH] move authoptions --- app/api/auth/[...nextauth]/route.ts | 17 +---------------- app/api/minecraft/actions.ts | 10 +++++----- app/api/minecraft/route.ts | 0 app/components/minecraft-login.tsx | 6 +++--- app/lib/auth.ts | 15 ++++++++++++++- 5 files changed, 23 insertions(+), 25 deletions(-) delete mode 100644 app/api/minecraft/route.ts diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index dea2d8c..c029228 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -1,20 +1,5 @@ import NextAuth from "next-auth"; -import type { NextAuthOptions } from "next-auth"; -import BoxyHQ from "next-auth/providers/boxyhq-saml"; - -// For more information on each option (and a full list of options) go to -// https://next-auth.js.org/configuration/options - -export const authOptions: NextAuthOptions = { - providers: [ - BoxyHQ({ - authorization: { params: { scope: "" } }, - issuer: process.env.AUTH_BOXYHQ_SAML_ISSUER, - clientId: process.env.AUTH_BOXYHQ_SAML_ID || "dummy", - clientSecret: process.env.AUTH_BOXYHQ_SAML_SECRET || "dummy", - }), - ], -}; +import {authOptions} from "@/app/lib/auth"; const handler = NextAuth(authOptions); diff --git a/app/api/minecraft/actions.ts b/app/api/minecraft/actions.ts index 973b56f..74ca19e 100644 --- a/app/api/minecraft/actions.ts +++ b/app/api/minecraft/actions.ts @@ -5,11 +5,11 @@ interface MojangResponse { name: string; } -export async function register(prevState: any, formData: FormData) { +export async function register(prevState, formData: FormData) { const username = formData.get("username").toString().toLowerCase(); if (!username) { - return { message: "Username is required" }; + return { message: "Username is required", loading: false}; } const response = await fetch( @@ -17,14 +17,14 @@ export async function register(prevState: any, formData: FormData) { ); if (response.status === 404 || !response.ok) { - return { message: "Username not found" }; + return { message: "Username not found", loading: false }; } const uuid = ((await response.json()) as MojangResponse).id; if (!uuid) { - return { message: "UUID not found" }; + return { message: "UUID not found", loading: false }; } - return { message: "Saved" }; + return { message: "Saved", loading: false }; } diff --git a/app/api/minecraft/route.ts b/app/api/minecraft/route.ts deleted file mode 100644 index e69de29..0000000 diff --git a/app/components/minecraft-login.tsx b/app/components/minecraft-login.tsx index 77423ca..405477b 100644 --- a/app/components/minecraft-login.tsx +++ b/app/components/minecraft-login.tsx @@ -7,7 +7,7 @@ import { register } from "../api/minecraft/actions"; import { cn } from "../lib/cn"; const initialState = { - message: "", + message: "Save", loading: false, }; @@ -26,10 +26,10 @@ export function MinecraftLogin() { id="minecraft-username" placeholder="Minecraft Username" /> -

{state?.message}

); diff --git a/app/lib/auth.ts b/app/lib/auth.ts index 6e120fe..2184951 100644 --- a/app/lib/auth.ts +++ b/app/lib/auth.ts @@ -4,8 +4,21 @@ import type { NextApiResponse, } from "next"; import { getServerSession } from "next-auth"; +import type { NextAuthOptions } from "next-auth"; +import BoxyHQ from "next-auth/providers/boxyhq-saml"; -import { authOptions } from "../api/auth/[...nextauth]/route"; +// For more information on each option (and a full list of options) go to +// https://next-auth.js.org/configuration/options +export const authOptions: NextAuthOptions = { + providers: [ + BoxyHQ({ + authorization: { params: { scope: "" } }, + issuer: process.env.AUTH_BOXYHQ_SAML_ISSUER, + clientId: process.env.AUTH_BOXYHQ_SAML_ID || "dummy", + clientSecret: process.env.AUTH_BOXYHQ_SAML_SECRET || "dummy", + }), + ], +}; // Use it in server contexts export function auth(