Spaces:
Runtime error
Runtime error
| import NextAuth from 'next-auth'; | |
| import CredentialsProvider from 'next-auth/providers/credentials'; | |
| export const authOptions = { | |
| providers: [ | |
| CredentialsProvider({ | |
| name: 'Developer Secure Access', | |
| credentials: { | |
| email: { label: "Email", type: "email" }, | |
| password: { label: "Password", type: "password" } | |
| }, | |
| async authorize(credentials) { | |
| // Secure check against environment variables | |
| // This ensures only the developer with access to deployment secrets can log in. | |
| const adminEmail = process.env.ADMIN_EMAIL; | |
| const adminPassword = process.env.ADMIN_PASSWORD; | |
| if (!adminEmail || !adminPassword) { | |
| console.error("Security Error: ADMIN_EMAIL or ADMIN_PASSWORD not set in environment."); | |
| return null; | |
| } | |
| if (credentials.email === adminEmail && credentials.password === adminPassword) { | |
| return { | |
| id: '1', | |
| name: 'Lead Developer', | |
| email: adminEmail, | |
| }; | |
| } | |
| return null; | |
| } | |
| }) | |
| ], | |
| pages: { | |
| signIn: '/', // Use home page for login to keep it contained | |
| error: '/', // Show errors on home page | |
| }, | |
| session: { | |
| strategy: 'jwt', | |
| maxAge: 24 * 60 * 60, // 24 hours | |
| }, | |
| callbacks: { | |
| async jwt({ token, user }) { | |
| if (user) { | |
| token.id = user.id; | |
| } | |
| return token; | |
| }, | |
| async session({ session, token }) { | |
| if (session.user) { | |
| session.user.id = token.id; | |
| } | |
| return session; | |
| }, | |
| }, | |
| secret: process.env.NEXTAUTH_SECRET, | |
| }; | |
| export default NextAuth(authOptions); |