2022-04-10 16:34:29 +00:00
|
|
|
import NextAuth from "next-auth";
|
|
|
|
import DiscordProvider from "next-auth/providers/discord";
|
2022-04-10 18:26:47 +00:00
|
|
|
import { PrismaAdapter } from "@next-auth/prisma-adapter";
|
|
|
|
import prisma from "../../../lib/prisma";
|
2022-04-10 16:34:29 +00:00
|
|
|
|
|
|
|
export default NextAuth({
|
2022-04-10 18:26:47 +00:00
|
|
|
adapter: PrismaAdapter(prisma),
|
2022-04-10 16:34:29 +00:00
|
|
|
providers: [
|
|
|
|
DiscordProvider({
|
|
|
|
clientId: process.env.DISCORD_CLIENT_ID,
|
|
|
|
clientSecret: process.env.DISCORD_CLIENT_SECRET,
|
|
|
|
}),
|
|
|
|
],
|
2022-04-10 18:26:47 +00:00
|
|
|
callbacks: {
|
2022-04-24 02:58:54 +00:00
|
|
|
async signIn({ user, account, profile, email, credentials }) {
|
2022-04-24 03:20:03 +00:00
|
|
|
// console.log(user, account, profile, email, credentials);
|
2022-04-24 02:58:54 +00:00
|
|
|
if (user.image != profile.image_url) {
|
|
|
|
await prisma.user.update({
|
|
|
|
data: {
|
|
|
|
image: profile.image_url,
|
|
|
|
},
|
|
|
|
where: {
|
|
|
|
id: user.id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2022-04-10 18:26:47 +00:00
|
|
|
async session({ session, token, user }) {
|
|
|
|
session.user.id = user.id;
|
2022-04-11 17:33:16 +00:00
|
|
|
// console.log(JSON.stringify(user));
|
2022-04-10 18:26:47 +00:00
|
|
|
return session;
|
|
|
|
},
|
|
|
|
},
|
2022-04-10 16:34:29 +00:00
|
|
|
});
|