export const authOptions: NextAuthOptions = {
callbacks: {
jwt: async ({ token, user }) => {
if (user) {
token.id = user.id;
token.email = user.email;
}
return token;
},
session: ({ session, token, user }) => ({
...session,
user: {
...session.user,
id: token.id || user.id,
},
}),
},
adapter: PrismaAdapter(db) as Adapter,
session: {
strategy: "jwt",
},
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: {
label: "Username",
type: "text",
placeholder: "jose@gmail.com",
},
password: { label: "Password", type: "password" },
},
async authorize(credentials, req) {
if (!credentials?.email || !credentials?.password) return null;
const user = await db.user.findUnique({
where: {
email: credentials.email.toLowerCase(),
},
});
if (!user?.passwordHash) return null;
const passwordsMatch = await bcrypt.compare(
credentials.password,
user.passwordHash,
);
if (!passwordsMatch) return null;
return user;
},
}),
],
};
export const authOptions: NextAuthOptions = {
callbacks: {
jwt: async ({ token, user }) => {
if (user) {
token.id = user.id;
token.email = user.email;
}
return token;
},
session: ({ session, token, user }) => ({
...session,
user: {
...session.user,
id: token.id || user.id,
},
}),
},
adapter: PrismaAdapter(db) as Adapter,
session: {
strategy: "jwt",
},
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: {
label: "Username",
type: "text",
placeholder: "jose@gmail.com",
},
password: { label: "Password", type: "password" },
},
async authorize(credentials, req) {
if (!credentials?.email || !credentials?.password) return null;
const user = await db.user.findUnique({
where: {
email: credentials.email.toLowerCase(),
},
});
if (!user?.passwordHash) return null;
const passwordsMatch = await bcrypt.compare(
credentials.password,
user.passwordHash,
);
if (!passwordsMatch) return null;
return user;
},
}),
],
};