- Add admin page at /admin (restricted to ADMIN_EMAIL via proxy) - Implement user ban/unban and deletion - Add daily puzzle creation, modification, deletion - Include 14-day activity chart with hover details - Add User.banned field to schema and migrate database - Block banned users from logging in - Add ADMIN_EMAIL to .env.local configuration - Update Prisma client after schema changes
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import NextAuth from "next-auth";
|
|
import Credentials from "next-auth/providers/credentials";
|
|
import bcrypt from "bcryptjs";
|
|
import { prisma } from "./lib/prisma";
|
|
|
|
export const { handlers, auth, signIn, signOut } = NextAuth({
|
|
providers: [
|
|
Credentials({
|
|
credentials: {
|
|
email: { label: "Email", type: "email" },
|
|
password: { label: "Mot de passe", type: "password" },
|
|
},
|
|
async authorize(credentials) {
|
|
if (!credentials?.email || !credentials?.password) return null;
|
|
const user = await prisma.user.findUnique({
|
|
where: { email: credentials.email as string },
|
|
});
|
|
if (!user) return null;
|
|
const valid = await bcrypt.compare(
|
|
credentials.password as string,
|
|
user.password,
|
|
);
|
|
if (!valid) return null;
|
|
if (user.banned) return null;
|
|
return { id: user.id, name: user.name, email: user.email };
|
|
},
|
|
}),
|
|
],
|
|
session: { strategy: "jwt" },
|
|
pages: {
|
|
signIn: "/",
|
|
},
|
|
callbacks: {
|
|
jwt({ token, user }) {
|
|
if (user) {
|
|
token.id = user.id;
|
|
token.email = user.email;
|
|
}
|
|
return token;
|
|
},
|
|
session({ session, token }) {
|
|
if (session.user) {
|
|
session.user.id = token.id as string;
|
|
session.user.email = token.email as string;
|
|
}
|
|
return session;
|
|
},
|
|
},
|
|
});
|