Skip to content

Commit

Permalink
move authoptions
Browse files Browse the repository at this point in the history
  • Loading branch information
C4illin committed Nov 18, 2024
1 parent ee4f20b commit 58713f2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
17 changes: 1 addition & 16 deletions app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
10 changes: 5 additions & 5 deletions app/api/minecraft/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ 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(
`https://api.mojang.com/users/profiles/minecraft/${username}`,
);

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 };
}
Empty file removed app/api/minecraft/route.ts
Empty file.
6 changes: 3 additions & 3 deletions app/components/minecraft-login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { register } from "../api/minecraft/actions";
import { cn } from "../lib/cn";

const initialState = {
message: "",
message: "Save",
loading: false,
};

Expand All @@ -26,10 +26,10 @@ export function MinecraftLogin() {
id="minecraft-username"
placeholder="Minecraft Username"
/>
<p aria-live="polite">{state?.message}</p>
<button
disabled={state?.loading}
type="submit"
aria-live="polite"
className={cn(`
flex w-full justify-center rounded bg-slate-700 p-2 text-sm/6 font-semibold text-white
shadow
Expand All @@ -39,7 +39,7 @@ export function MinecraftLogin() {
hover:bg-slate-500
`)}
>
Save
{state?.message || "Save"}
</button>
</Form>
);
Expand Down
15 changes: 14 additions & 1 deletion app/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 58713f2

Please sign in to comment.