mirror of
https://github.com/UiO-Gaming/name-100-uio-gamers.git
synced 2026-11-05 13:56:53 +01:00
move auth handler and fix type issues
This commit is contained in:
5 files changed
+46
-45
No files matched your search
@@ -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,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,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";
|
||||
|
||||
@@ -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
@@ -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";
|
||||
|
||||
Reference in new issue
Block a user