Initial commit - SaveTheMoment Atlas Basis-Setup

This commit is contained in:
Dennis Forte
2025-11-12 20:21:32 +01:00
commit 0b6e429329
167 changed files with 30843 additions and 0 deletions

75
lib/auth.ts Normal file
View File

@@ -0,0 +1,75 @@
import { NextAuthOptions } from 'next-auth';
import CredentialsProvider from 'next-auth/providers/credentials';
import { compare } from 'bcryptjs';
import { prisma } from './prisma';
export const authOptions: NextAuthOptions = {
session: {
strategy: 'jwt',
},
pages: {
signIn: '/login',
},
providers: [
CredentialsProvider({
name: 'credentials',
credentials: {
email: { label: 'Email', type: 'email' },
password: { label: 'Password', type: 'password' },
},
async authorize(credentials) {
if (!credentials?.email || !credentials?.password) {
return null;
}
const user = await prisma.user.findUnique({
where: {
email: credentials.email,
},
});
if (!user || !user.active) {
return null;
}
const isPasswordValid = await compare(
credentials.password,
user.password
);
if (!isPasswordValid) {
return null;
}
return {
id: user.id,
email: user.email,
name: user.name,
role: user.role,
};
},
}),
],
callbacks: {
async jwt({ token, user }) {
if (user) {
return {
...token,
id: user.id,
role: user.role,
};
}
return token;
},
async session({ session, token }) {
return {
...session,
user: {
...session.user,
id: token.id,
role: token.role,
},
};
},
},
};