feat: username/ww login, tijdzone fix, Vannacht → Eergisternacht"
Some checks failed
Build & Deploy / build (push) Failing after 1m11s
Some checks failed
Build & Deploy / build (push) Failing after 1m11s
This commit is contained in:
@@ -1,33 +1,47 @@
|
||||
import { NextAuthOptions } from "next-auth";
|
||||
import DiscordProvider from "next-auth/providers/discord";
|
||||
import CredentialsProvider from "next-auth/providers/credentials";
|
||||
import { PrismaAdapter } from "@next-auth/prisma-adapter";
|
||||
import bcrypt from "bcryptjs";
|
||||
import { prisma } from "./prisma";
|
||||
|
||||
export const authOptions: NextAuthOptions = {
|
||||
adapter: PrismaAdapter(prisma),
|
||||
// JWT strategy zodat de middleware de sessie kan verifieren
|
||||
// zonder een database call te doen bij elk request
|
||||
session: {
|
||||
strategy: "jwt",
|
||||
},
|
||||
session: { strategy: "jwt" },
|
||||
providers: [
|
||||
DiscordProvider({
|
||||
clientId: process.env.DISCORD_CLIENT_ID!,
|
||||
clientSecret: process.env.DISCORD_CLIENT_SECRET!,
|
||||
}),
|
||||
CredentialsProvider({
|
||||
name: "credentials",
|
||||
credentials: {
|
||||
username: { label: "Gebruikersnaam", type: "text" },
|
||||
password: { label: "Wachtwoord", type: "password" },
|
||||
},
|
||||
async authorize(credentials) {
|
||||
if (!credentials?.username || !credentials?.password) return null;
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { username: credentials.username },
|
||||
});
|
||||
|
||||
if (!user?.password) return null;
|
||||
|
||||
const valid = await bcrypt.compare(credentials.password, user.password);
|
||||
if (!valid) return null;
|
||||
|
||||
return { id: user.id, name: user.name, email: user.email, image: user.image };
|
||||
},
|
||||
}),
|
||||
],
|
||||
callbacks: {
|
||||
jwt({ token, user }) {
|
||||
// user is alleen aanwezig bij eerste login
|
||||
if (user) {
|
||||
token.id = user.id;
|
||||
}
|
||||
if (user) token.id = user.id;
|
||||
return token;
|
||||
},
|
||||
session({ session, token }) {
|
||||
if (session.user) {
|
||||
session.user.id = token.id as string;
|
||||
}
|
||||
if (session.user) session.user.id = token.id as string;
|
||||
return session;
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user