Files
Compass/auth.ts
MartinBraquet f67ffa2701 Set Google Auth
2025-07-27 20:44:25 +02:00

61 lines
1.8 KiB
TypeScript

import CredentialsProvider from "next-auth/providers/credentials";
import GoogleProvider from "next-auth/providers/google";
import {type NextAuthOptions} from "next-auth";
import bcrypt from "bcryptjs";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import {prisma} from "@/lib/prisma"
export const authOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
}),
CredentialsProvider({
name: "credentials",
credentials: {
email: {label: "Email", type: "email"},
name: {label: "Name", type: "name"},
password: {label: "Password", type: "password"},
},
async authorize(credentials) {
if (!credentials?.email || !credentials?.password) {
throw new Error("Email and password are required");
}
const user = await prisma.user.findUnique({
where: {email: credentials.email},
});
if (!user || !user.password) {
throw new Error("Invalid email or password");
}
const isCorrectPassword = await bcrypt.compare(
credentials.password,
user.password
);
if (!isCorrectPassword) {
throw new Error("Invalid email or password");
}
return user;
},
}),
],
pages: {
signIn: "/login",
},
adapter: PrismaAdapter(prisma),
debug: process.env.NODE_ENV === "development",
secret: process.env.NEXTAUTH_SECRET,
// callbacks: {
// async jwt({ token, user }) {
// return { ...token, id: token.id ?? user?.id };
// },
// async session({ session, token }) {
// return { ...session, user: { ...session.user, id: token.id } };
// },
// },
} satisfies NextAuthOptions;