Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { PrismaAdapter } from "@next-auth/prisma-adapter";
- import { type GetServerSidePropsContext } from "next";
- import {
- getServerSession,
- type DefaultSession,
- type NextAuthOptions,
- } from "next-auth";
- import DiscordProvider from "next-auth/providers/discord";
- import { env } from "~/env.mjs";
- import { db } from "~/server/db";
- /**
- * Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
- * object and keep type safety.
- *
- * @see https://next-auth.js.org/getting-started/typescript#module-augmentation
- */
- declare module "next-auth" {
- interface Session extends DefaultSession {
- user: DefaultSession["user"] & {
- id: string;
- // ...other properties
- // role: UserRole;
- };
- }
- }
- export const authOptions: NextAuthOptions = {
- callbacks: {
- session: async ({ session, token, user }) => {
- console.log(Promise.resolve(token));
- return {
- ...session,
- user: {
- ...session.user,
- id: user.id,
- },
- };
- },
- },
- adapter: PrismaAdapter(db),
- providers: [
- DiscordProvider({
- clientId: env.DISCORD_CLIENT_ID,
- clientSecret: env.DISCORD_CLIENT_SECRET,
- authorization: {
- params: {
- scope: "identify guilds email",
- },
- },
- }),
- ],
- };
- export const getServerAuthSession = (ctx: {
- req: GetServerSidePropsContext["req"];
- res: GetServerSidePropsContext["res"];
- }) => {
- return getServerSession(ctx.req, ctx.res, authOptions);
- };
Advertisement
Add Comment
Please, Sign In to add comment