mirror of
https://gitea.gofwd.group/sean/gunbuilder-next-tailwind.git
synced 2025-12-06 02:56:45 -05:00
nextauth working.
This commit is contained in:
70
src/app/api/auth/[...nextauth]/route.ts
Normal file
70
src/app/api/auth/[...nextauth]/route.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import NextAuth from 'next-auth';
|
||||
import GoogleProvider from 'next-auth/providers/google';
|
||||
import CredentialsProvider from 'next-auth/providers/credentials';
|
||||
|
||||
// In-memory user store (for demo only)
|
||||
type User = { email: string; password: string };
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var _users: User[] | undefined;
|
||||
}
|
||||
const users: User[] = global._users || (global._users = []);
|
||||
|
||||
const handler = NextAuth({
|
||||
providers: [
|
||||
GoogleProvider({
|
||||
clientId: process.env.GOOGLE_CLIENT_ID ?? '',
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? '',
|
||||
}),
|
||||
CredentialsProvider({
|
||||
name: 'Credentials',
|
||||
credentials: {
|
||||
email: { label: "Email", type: "email" },
|
||||
password: { label: "Password", type: "password" }
|
||||
},
|
||||
async authorize(credentials) {
|
||||
if (!credentials?.email || !credentials?.password) return null;
|
||||
// Check in-memory user store
|
||||
const user = users.find(
|
||||
(u) => u.email === credentials.email && u.password === credentials.password
|
||||
);
|
||||
if (user) {
|
||||
return {
|
||||
id: user.email,
|
||||
email: user.email,
|
||||
name: user.email.split('@')[0],
|
||||
};
|
||||
}
|
||||
// For demo, still allow the test user
|
||||
if (credentials.email === "test@example.com" && credentials.password === "password") {
|
||||
return {
|
||||
id: "1",
|
||||
email: credentials.email,
|
||||
name: "Test User",
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}),
|
||||
],
|
||||
pages: {
|
||||
signIn: '/account/login',
|
||||
// signUp: '/account/register', // Uncomment when register page is ready
|
||||
// error: '/account/error', // Uncomment when error page is ready
|
||||
},
|
||||
callbacks: {
|
||||
async session({ session, token }) {
|
||||
// Add any additional user data to the session here
|
||||
return session;
|
||||
},
|
||||
async jwt({ token, user }) {
|
||||
// Add any additional user data to the JWT here
|
||||
if (user) {
|
||||
token.id = user.id;
|
||||
}
|
||||
return token;
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export { handler as GET, handler as POST }
|
||||
Reference in New Issue
Block a user