borders/pages/api/auth/[...nextauth].js
2022-04-23 23:20:03 -04:00

35 lines
968 B
JavaScript

import NextAuth from "next-auth";
import DiscordProvider from "next-auth/providers/discord";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import prisma from "../../../lib/prisma";
export default NextAuth({
adapter: PrismaAdapter(prisma),
providers: [
DiscordProvider({
clientId: process.env.DISCORD_CLIENT_ID,
clientSecret: process.env.DISCORD_CLIENT_SECRET,
}),
],
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
// console.log(user, account, profile, email, credentials);
if (user.image != profile.image_url) {
await prisma.user.update({
data: {
image: profile.image_url,
},
where: {
id: user.id,
},
});
}
return true;
},
async session({ session, token, user }) {
session.user.id = user.id;
// console.log(JSON.stringify(user));
return session;
},
},
});