Files
nextjs-boilerplate/lib/auth.ts
T

53 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import NextAuth from "next-auth"
import CredentialsProvider from "next-auth/providers/credentials"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: { label: "Email", type: "email" },
password: { label: "Password", type: "password" }
},
async authorize(credentials) {
// Gerçek AyrisLegal kullanıcı sistemine (Supabase Auth) bağlı DEĞİL —
// admin paneli girişi bilerek ayrı, basit bir env-tabanlı kontrol.
// ADMIN_EMAIL / ADMIN_PASSWORD .env dosyasında tanımlı, sadece
// server-side (bu fonksiyon) okunuyor, hiçbir zaman client'a gitmiyor.
const adminEmail = process.env.ADMIN_EMAIL
const adminPassword = process.env.ADMIN_PASSWORD
if (!adminEmail || !adminPassword) return null
if (credentials?.email === adminEmail && credentials?.password === adminPassword) {
return {
id: "1",
name: "Admin",
email: adminEmail,
role: "ADMIN"
}
}
return null
}
})
],
callbacks: {
async jwt({ token, user }) {
if (user) {
token.role = (user as any).role
}
return token
},
async session({ session, token }) {
if (session.user && token.role) {
(session.user as any).role = token.role
}
return session
}
},
pages: {
signIn: '/login'
}
})