amati/src/features/auth/index.ts
2024-01-08 00:44:14 +07:00

41 lines
1014 B
TypeScript

import NextAuth from "next-auth";
import emailPasswordProvider from "./providers/emailPasswordProvider";
import prisma from "@/db";
import { PrismaAdapter } from "@auth/prisma-adapter";
const nextAuth = NextAuth({
adapter: PrismaAdapter(prisma),
session: {
strategy: "jwt"
},
providers:[
emailPasswordProvider
],
callbacks: {
session: async({session, user, token}) => {
if (session.user){
session.user.id = token.userId as string;
}
return session;
},
jwt: async ({ token, user, account, profile }) => {
if(account && account.type === "credentials") {
token.userId = account.providerAccountId; // this is Id that coming from authorize() callback
}
return token
}
},
pages: {
signIn: "/login"
}
});
export const {
signIn,
signOut,
handlers: { GET, POST},
auth
} = nextAuth;
export default nextAuth;