Guest User

Untitled

a guest
Apr 13th, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import prisma from "@/lib/database";
  2. import NextAuth from "next-auth";
  3. import DiscordProvider from "next-auth/providers/discord";
  4.  
  5. const handler = NextAuth({
  6. secret: process.env.NEXTAUTH_SECRET,
  7. providers: [
  8. DiscordProvider({
  9. clientId: process.env.NEXT_PUBLIC_CLIENT_ID!,
  10. clientSecret: process.env.NEXT_PUBLIC_CLIENT_SECRET!,
  11. authorization: {
  12. params: {
  13. scope: ["identify", "email", "guilds"].join(" "),
  14. },
  15. },
  16. token: "https://discord.com/api/oauth2/token",
  17. userinfo: "https://discord.com/api/users/@me",
  18. profile(profile) {
  19. if (profile.avatar === null) {
  20. const defaultAvatarNumber = parseInt(profile.discriminator) % 5;
  21. profile.avatar = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNumber}.png`;
  22. } else {
  23. const format = profile.avatar.startsWith("a_") ? "gif" : "png";
  24. profile.avatar = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`;
  25. }
  26.  
  27. return {
  28. id: profile.id,
  29. name: profile.username,
  30. image: profile.avatar,
  31. ...profile,
  32. };
  33. },
  34. }),
  35. ],
  36. callbacks: {
  37. async jwt({ token, account, profile, user }) {
  38. return {
  39. ...token,
  40. ...account,
  41. ...profile,
  42. ...user,
  43. };
  44. },
  45. async session({ session, token }) {
  46. session.user.id = token?.id as string;
  47. return {
  48. ...session,
  49. };
  50. },
  51. },
  52. pages: {
  53. signIn: "/",
  54. },
  55. });
  56. export { handler as GET, handler as POST };
  57.  
Advertisement
Add Comment
Please, Sign In to add comment