removed console.log statements
This commit is contained in:
@@ -1,67 +1,66 @@
|
||||
import {
|
||||
AuthOptions,
|
||||
getServerSession as getNextAuthServerSession,
|
||||
} from 'next-auth';
|
||||
import { PrismaAdapter } from '@next-auth/prisma-adapter';
|
||||
import Credentials from 'next-auth/providers/credentials';
|
||||
import { PrismaClient } from '@repo/db';
|
||||
import bcrypt from 'bcryptjs';
|
||||
AuthOptions,
|
||||
getServerSession as getNextAuthServerSession,
|
||||
} from "next-auth";
|
||||
import { PrismaAdapter } from "@next-auth/prisma-adapter";
|
||||
import Credentials from "next-auth/providers/credentials";
|
||||
import { PrismaClient } from "@repo/db";
|
||||
import bcrypt from "bcryptjs";
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export const options: AuthOptions = {
|
||||
providers: [
|
||||
Credentials({
|
||||
credentials: {
|
||||
email: { label: 'Email', type: 'email', placeholder: 'E-Mail' },
|
||||
password: { label: 'Password', type: 'password' },
|
||||
},
|
||||
async authorize(credentials, req) {
|
||||
try {
|
||||
if (!credentials) throw new Error('No credentials provided');
|
||||
const user = await prisma.user.findFirstOrThrow({
|
||||
where: { email: credentials.email },
|
||||
});
|
||||
if (bcrypt.compareSync(credentials.password, user.password)) {
|
||||
console.log('User found and password correct', user);
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
}),
|
||||
],
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
session: {
|
||||
strategy: 'jwt',
|
||||
maxAge: 30 * 24 * 60 * 60,
|
||||
},
|
||||
providers: [
|
||||
Credentials({
|
||||
credentials: {
|
||||
email: { label: "Email", type: "email", placeholder: "E-Mail" },
|
||||
password: { label: "Password", type: "password" },
|
||||
},
|
||||
async authorize(credentials, req) {
|
||||
try {
|
||||
if (!credentials) throw new Error("No credentials provided");
|
||||
const user = await prisma.user.findFirstOrThrow({
|
||||
where: { email: credentials.email },
|
||||
});
|
||||
if (bcrypt.compareSync(credentials.password, user.password)) {
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
}),
|
||||
],
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
session: {
|
||||
strategy: "jwt",
|
||||
maxAge: 30 * 24 * 60 * 60,
|
||||
},
|
||||
|
||||
adapter: PrismaAdapter(prisma as any),
|
||||
callbacks: {
|
||||
jwt: async ({ token, user }) => {
|
||||
if (user && 'firstname' in user) {
|
||||
return {
|
||||
...token,
|
||||
...user,
|
||||
};
|
||||
}
|
||||
return token;
|
||||
},
|
||||
session: async ({ session, user, token }) => {
|
||||
return {
|
||||
...session,
|
||||
user: token,
|
||||
};
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
signIn: '/login',
|
||||
signOut: '/logout',
|
||||
error: '/authError',
|
||||
newUser: '/register',
|
||||
},
|
||||
adapter: PrismaAdapter(prisma as any),
|
||||
callbacks: {
|
||||
jwt: async ({ token, user }) => {
|
||||
if (user && "firstname" in user) {
|
||||
return {
|
||||
...token,
|
||||
...user,
|
||||
};
|
||||
}
|
||||
return token;
|
||||
},
|
||||
session: async ({ session, user, token }) => {
|
||||
return {
|
||||
...session,
|
||||
user: token,
|
||||
};
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
signIn: "/login",
|
||||
signOut: "/logout",
|
||||
error: "/authError",
|
||||
newUser: "/register",
|
||||
},
|
||||
} satisfies AuthOptions;
|
||||
|
||||
export const getServerSession = async () => getNextAuthServerSession(options);
|
||||
|
||||
Reference in New Issue
Block a user