Guest User

Untitled

a guest
Sep 21st, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { PrismaAdapter } from "@next-auth/prisma-adapter";
  2. import { type GetServerSidePropsContext } from "next";
  3. import {
  4.   getServerSession,
  5.   type DefaultSession,
  6.   type NextAuthOptions,
  7. } from "next-auth";
  8. import DiscordProvider from "next-auth/providers/discord";
  9.  
  10. import { env } from "~/env.mjs";
  11. import { db } from "~/server/db";
  12.  
  13. /**
  14.  * Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
  15.  * object and keep type safety.
  16.  *
  17.  * @see https://next-auth.js.org/getting-started/typescript#module-augmentation
  18.  */
  19. declare module "next-auth" {
  20.   interface Session extends DefaultSession {
  21.     user: DefaultSession["user"] & {
  22.       id: string;
  23.       // ...other properties
  24.       // role: UserRole;
  25.     };
  26.   }
  27. }
  28.  
  29. export const authOptions: NextAuthOptions = {
  30.   callbacks: {
  31.     session: async ({ session, token, user }) => {
  32.       console.log(Promise.resolve(token));
  33.       return {
  34.         ...session,
  35.         user: {
  36.           ...session.user,
  37.           id: user.id,
  38.         },
  39.       };
  40.     },
  41.   },
  42.   adapter: PrismaAdapter(db),
  43.   providers: [
  44.     DiscordProvider({
  45.       clientId: env.DISCORD_CLIENT_ID,
  46.       clientSecret: env.DISCORD_CLIENT_SECRET,
  47.       authorization: {
  48.         params: {
  49.           scope: "identify guilds email",
  50.         },
  51.       },
  52.     }),
  53.   ],
  54. };
  55.  
  56. export const getServerAuthSession = (ctx: {
  57.   req: GetServerSidePropsContext["req"];
  58.   res: GetServerSidePropsContext["res"];
  59. }) => {
  60.   return getServerSession(ctx.req, ctx.res, authOptions);
  61. };
  62.  
Advertisement
Add Comment
Please, Sign In to add comment