00Boobs00 commited on
Commit
7ee9dc8
·
verified ·
1 Parent(s): 68d813f

Upload pages/api/auth/[...nextauth].js with huggingface_hub

Browse files
Files changed (1) hide show
  1. 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 GoogleProvider from 'next-auth/providers/google';
3
- import GitHubProvider from 'next-auth/providers/github';
4
 
5
  export const authOptions = {
6
  providers: [
7
- GoogleProvider({
8
- clientId: process.env.GOOGLE_CLIENT_ID || 'mock-google-id',
9
- clientSecret: process.env.GOOGLE_CLIENT_SECRET || 'mock-google-secret',
10
- }),
11
- GitHubProvider({
12
- clientId: process.env.GITHUB_ID || 'mock-github-id',
13
- clientSecret: process.env.GITHUB_SECRET || 'mock-github-secret',
14
- }),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  ],
16
  pages: {
17
- signIn: '/auth/signin',
18
- error: '/auth/error',
 
 
 
 
19
  },
20
  callbacks: {
21
- async jwt({ token, account }) {
22
- if (account) {
23
- token.accessToken = account.access_token;
24
  }
25
  return token;
26
  },
27
  async session({ session, token }) {
28
- session.accessToken = token.accessToken;
 
 
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
  },