Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import prisma from "@/lib/database";
- import NextAuth from "next-auth";
- import DiscordProvider from "next-auth/providers/discord";
- const handler = NextAuth({
- secret: process.env.NEXTAUTH_SECRET,
- providers: [
- DiscordProvider({
- clientId: process.env.NEXT_PUBLIC_CLIENT_ID!,
- clientSecret: process.env.NEXT_PUBLIC_CLIENT_SECRET!,
- authorization: {
- params: {
- scope: ["identify", "email", "guilds"].join(" "),
- },
- },
- token: "https://discord.com/api/oauth2/token",
- userinfo: "https://discord.com/api/users/@me",
- profile(profile) {
- if (profile.avatar === null) {
- const defaultAvatarNumber = parseInt(profile.discriminator) % 5;
- profile.avatar = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNumber}.png`;
- } else {
- const format = profile.avatar.startsWith("a_") ? "gif" : "png";
- profile.avatar = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`;
- }
- return {
- id: profile.id,
- name: profile.username,
- image: profile.avatar,
- ...profile,
- };
- },
- }),
- ],
- callbacks: {
- async jwt({ token, account, profile, user }) {
- return {
- ...token,
- ...account,
- ...profile,
- ...user,
- };
- },
- async session({ session, token }) {
- session.user.id = token?.id as string;
- return {
- ...session,
- };
- },
- },
- pages: {
- signIn: "/",
- },
- });
- export { handler as GET, handler as POST };
Advertisement
Add Comment
Please, Sign In to add comment