57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import NextAuth from "next-auth";
|
|
import Credentials from "next-auth/providers/credentials";
|
|
|
|
export const {
|
|
handlers: { GET, POST },
|
|
auth,
|
|
signIn,
|
|
signOut,
|
|
} = NextAuth({
|
|
providers: [
|
|
Credentials({
|
|
name: "Credentials",
|
|
credentials: {
|
|
email: { label: "Email", type: "email" },
|
|
password: { label: "Password", type: "password" },
|
|
},
|
|
async authorize(credentials) {
|
|
const adminEmail = process.env.ADMIN_EMAIL;
|
|
const adminPassword = process.env.ADMIN_PASSWORD;
|
|
|
|
if (
|
|
credentials?.email === adminEmail &&
|
|
credentials?.password === adminPassword
|
|
) {
|
|
return {
|
|
id: "admin",
|
|
name: "Admin",
|
|
email: adminEmail,
|
|
};
|
|
}
|
|
|
|
return null;
|
|
},
|
|
}),
|
|
],
|
|
pages: {
|
|
signIn: "/admin/login",
|
|
},
|
|
session: {
|
|
strategy: "jwt",
|
|
},
|
|
callbacks: {
|
|
async jwt({ token, user }) {
|
|
if (user) {
|
|
token.id = user.id;
|
|
}
|
|
return token;
|
|
},
|
|
async session({ session, token }) {
|
|
if (token?.id) {
|
|
session.user.id = token.id as string;
|
|
}
|
|
return session;
|
|
},
|
|
},
|
|
});
|