move auth handler and fix type issues

This commit is contained in:
leander committed 2025-06-22 02:37:21 +02:00
1 parent aa76b21282
commit 7764d98f14
5 files changed
+46 -45

No files matched your search

+1 -42
View File
@@ -1,46 +1,5 @@
import { verifyUserRole } from "@/lib/discord";
import type { NextAuthOptions } from "next-auth";
import NextAuth from "next-auth";
import DiscordProvider, { type DiscordProfile } from "next-auth/providers/discord";
export const authOptions: NextAuthOptions = {
providers: [
DiscordProvider({
clientId: process.env.DISCORD_CLIENT_ID as string,
clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
profile(profile: DiscordProfile) {
if (profile.avatar === null) {
const defaultAvatarNumber = parseInt(profile.discriminator) % 5;
profile.image_url = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNumber}.png`;
} else {
const format = profile.avatar.startsWith("a_") ? "gif" : "png";
profile.image_url = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`;
}
return {
id: profile.id,
name: profile.global_name ?? profile.username,
email: profile.email,
image: profile.image_url,
};
},
}),
],
callbacks: {
async signIn({ user }) {
const hasRequiredRole = await verifyUserRole(user.id);
if (!hasRequiredRole) {
return false;
}
return true;
},
},
pages: {
error: "/auth/error",
},
secret: process.env.NEXTAUTH_SECRET,
};
import { authOptions } from "../../../lib/auth";
const handler = NextAuth(authOptions);
+1 -1
View File
@@ -1,4 +1,4 @@
import { authOptions } from "@/api/auth/[...nextauth]/route";
import { authOptions } from "@/lib/auth";
import type { Match } from "@/types";
import { getServerSession } from "next-auth/next";
import { NextResponse } from "next/server";
+1 -1
View File
@@ -1,5 +1,5 @@
import { authOptions } from "@/api/auth/[...nextauth]/route";
import { LanguageProvider } from "@/LanguageContext";
import { authOptions } from "@/lib/auth";
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";
import AuthErrorClient from "./AuthErrorClient";
+42
View File
@@ -0,0 +1,42 @@
import { verifyUserRole } from "@/lib/discord";
import type { NextAuthOptions } from "next-auth";
import DiscordProvider, { type DiscordProfile } from "next-auth/providers/discord";
export const authOptions: NextAuthOptions = {
providers: [
DiscordProvider({
clientId: process.env.DISCORD_CLIENT_ID as string,
clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
profile(profile: DiscordProfile) {
if (profile.avatar === null) {
const defaultAvatarNumber = parseInt(profile.discriminator) % 5;
profile.image_url = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNumber}.png`;
} else {
const format = profile.avatar.startsWith("a_") ? "gif" : "png";
profile.image_url = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`;
}
return {
id: profile.id,
name: profile.global_name ?? profile.username,
email: profile.email,
image: profile.image_url,
};
},
}),
],
callbacks: {
async signIn({ user }) {
const hasRequiredRole = await verifyUserRole(user.id);
if (!hasRequiredRole) {
return false;
}
return true;
},
},
pages: {
error: "/auth/error",
},
secret: process.env.NEXTAUTH_SECRET,
};
+1 -1
View File
@@ -1,5 +1,5 @@
import { authOptions } from "@/api/auth/[...nextauth]/route";
import { LanguageProvider } from "@/LanguageContext";
import { authOptions } from "@/lib/auth";
import { getServerSession } from "next-auth";
import HomeClient from "./components/HomeClient";
import LoginClient from "./components/LoginClient";