Spaces:
Runtime error
Runtime error
Upload pages/api/auth/[...nextauth].js with huggingface_hub
Browse files- pages/api/auth/[...nextauth].js +41 -16
pages/api/auth/[...nextauth].js
CHANGED
|
@@ -1,31 +1,56 @@
|
|
| 1 |
import NextAuth from 'next-auth';
|
| 2 |
-
import
|
| 3 |
-
import GitHubProvider from 'next-auth/providers/github';
|
| 4 |
|
| 5 |
export const authOptions = {
|
| 6 |
providers: [
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
],
|
| 16 |
pages: {
|
| 17 |
-
signIn: '/
|
| 18 |
-
error: '/
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
},
|
| 20 |
callbacks: {
|
| 21 |
-
async jwt({ token,
|
| 22 |
-
if (
|
| 23 |
-
token.
|
| 24 |
}
|
| 25 |
return token;
|
| 26 |
},
|
| 27 |
async session({ session, token }) {
|
| 28 |
-
session.
|
|
|
|
|
|
|
| 29 |
return session;
|
| 30 |
},
|
| 31 |
},
|
|
|
|
| 1 |
import NextAuth from 'next-auth';
|
| 2 |
+
import CredentialsProvider from 'next-auth/providers/credentials';
|
|
|
|
| 3 |
|
| 4 |
export const authOptions = {
|
| 5 |
providers: [
|
| 6 |
+
CredentialsProvider({
|
| 7 |
+
name: 'Developer Secure Access',
|
| 8 |
+
credentials: {
|
| 9 |
+
email: { label: "Email", type: "email" },
|
| 10 |
+
password: { label: "Password", type: "password" }
|
| 11 |
+
},
|
| 12 |
+
async authorize(credentials) {
|
| 13 |
+
// Secure check against environment variables
|
| 14 |
+
// This ensures only the developer with access to deployment secrets can log in.
|
| 15 |
+
const adminEmail = process.env.ADMIN_EMAIL;
|
| 16 |
+
const adminPassword = process.env.ADMIN_PASSWORD;
|
| 17 |
+
|
| 18 |
+
if (!adminEmail || !adminPassword) {
|
| 19 |
+
console.error("Security Error: ADMIN_EMAIL or ADMIN_PASSWORD not set in environment.");
|
| 20 |
+
return null;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
if (credentials.email === adminEmail && credentials.password === adminPassword) {
|
| 24 |
+
return {
|
| 25 |
+
id: '1',
|
| 26 |
+
name: 'Lead Developer',
|
| 27 |
+
email: adminEmail,
|
| 28 |
+
};
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
return null;
|
| 32 |
+
}
|
| 33 |
+
})
|
| 34 |
],
|
| 35 |
pages: {
|
| 36 |
+
signIn: '/', // Use home page for login to keep it contained
|
| 37 |
+
error: '/', // Show errors on home page
|
| 38 |
+
},
|
| 39 |
+
session: {
|
| 40 |
+
strategy: 'jwt',
|
| 41 |
+
maxAge: 24 * 60 * 60, // 24 hours
|
| 42 |
},
|
| 43 |
callbacks: {
|
| 44 |
+
async jwt({ token, user }) {
|
| 45 |
+
if (user) {
|
| 46 |
+
token.id = user.id;
|
| 47 |
}
|
| 48 |
return token;
|
| 49 |
},
|
| 50 |
async session({ session, token }) {
|
| 51 |
+
if (session.user) {
|
| 52 |
+
session.user.id = token.id;
|
| 53 |
+
}
|
| 54 |
return session;
|
| 55 |
},
|
| 56 |
},
|