Spaces:
Runtime error
Runtime error
File size: 1,634 Bytes
3302c0f 7ee9dc8 3302c0f 7ee9dc8 3302c0f 7ee9dc8 3302c0f 7ee9dc8 3302c0f 7ee9dc8 3302c0f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
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); |