mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
Add hunts table and default row; improve error handling and UI for team management
This commit is contained in:
1 parent
cd9c106ba1
commit
a6ed24b2e6
8 files changed
+156
-52
No files matched your search
@@ -1,33 +1,49 @@
|
||||
export const runtime = "nodejs";
|
||||
import NextAuth from "next-auth";
|
||||
import CredentialsProvider from "next-auth/providers/credentials";
|
||||
import { validateCredentials } from "@/actions/auth";
|
||||
|
||||
// Ensure NEXTAUTH_SECRET is defined
|
||||
if (!process.env.NEXTAUTH_SECRET) {
|
||||
console.error("Warning: NEXTAUTH_SECRET is not defined");
|
||||
}
|
||||
|
||||
// Ensure NEXTAUTH_URL is defined
|
||||
if (!process.env.NEXTAUTH_URL) {
|
||||
console.error("Warning: NEXTAUTH_URL is not defined");
|
||||
}
|
||||
|
||||
export const authOptions = {
|
||||
debug: process.env.NODE_ENV === "development",
|
||||
providers: [
|
||||
CredentialsProvider({
|
||||
{
|
||||
id: "credentials",
|
||||
name: "Credentials",
|
||||
type: "credentials",
|
||||
credentials: {
|
||||
username: { label: "Username", type: "text" },
|
||||
password: { label: "Password", type: "password" },
|
||||
},
|
||||
async authorize(credentials) {
|
||||
if (!credentials?.username || !credentials?.password) return null;
|
||||
const user = await validateCredentials(
|
||||
credentials.username,
|
||||
credentials.password
|
||||
);
|
||||
return user
|
||||
? {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
role: user.role,
|
||||
teamId: user.teamId,
|
||||
}
|
||||
: null;
|
||||
try {
|
||||
if (!credentials?.username || !credentials?.password) return null;
|
||||
const user = await validateCredentials(
|
||||
credentials.username,
|
||||
credentials.password
|
||||
);
|
||||
return user
|
||||
? {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
role: user.role,
|
||||
teamId: user.teamId,
|
||||
}
|
||||
: null;
|
||||
} catch (error) {
|
||||
console.error("NextAuth authorize error:", error);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
}),
|
||||
},
|
||||
],
|
||||
callbacks: {
|
||||
async jwt({ token, user }) {
|
||||
@@ -50,10 +66,11 @@ export const authOptions = {
|
||||
return session;
|
||||
},
|
||||
},
|
||||
pages: { signIn: "/login" },
|
||||
// no "pages" property
|
||||
session: { strategy: "jwt", maxAge: 30 * 24 * 60 * 60 },
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
};
|
||||
|
||||
// Creating the handler after exporting authOptions
|
||||
const handler = NextAuth(authOptions);
|
||||
export { handler as GET, handler as POST };
|
||||
Reference in new issue
Block a user