- Implement user registration and login with NextAuth v5 (email/password, JWT) - Add authentication modal in UI with login/register tabs - Create user profile screen showing game statistics and history - Integrate Prisma 7 ORM with SQLite database for data persistence - Store game results (mode, path, clicks, time) in database - Auto-save completed games only when user is authenticated - Separate business logic into reusable hooks (useSoloGame, useMultiGame) - Organize UI into composable screen components (HomeScreen, SoloScreen, ProfileScreen, etc) - Add session persistence across F5 refresh for solo and multiplayer - Style auth modal, account button, and profile stats dashboard
40 lines
1.2 KiB
TypeScript
40 lines
1.2 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;
|
|
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;
|
|
return token;
|
|
},
|
|
session({ session, token }) {
|
|
if (session.user) session.user.id = token.id as string;
|
|
return session;
|
|
},
|
|
},
|
|
});
|