mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 14:32:11 +01:00
feat: Add authentication and session management with NextAuth.js and Prisma [broken]
- Implemented API session retrieval in `lib/api-auth.ts` to manage user sessions. - Created authentication options in `lib/auth-options.ts` using NextAuth.js with credentials provider. - Added migration scripts to create necessary tables for authentication in `migrations/0002_create_auth_tables.sql` and `prisma/migrations/20250601033219_add_nextauth_tables/migration.sql`. - Configured ESLint with Next.js and TypeScript support in `eslint.config.mjs`. - Updated Next.js configuration in `next.config.ts` for Cloudflare compatibility. - Defined Cloudflare Worker configuration in `open-next.config.ts` and `wrangler.jsonc`. - Enhanced type definitions for authentication in `types/auth.d.ts`. - Created a Cloudflare Worker entry point in `src/index.ts.backup` to handle API requests and responses.
This commit is contained in:
@ -31,11 +31,28 @@ export default function UserManagementPage() {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await fetch("/api/dashboard/users");
|
||||
const data = (await res.json()) as UsersApiResponse;
|
||||
setUsers(data.users);
|
||||
const data = await res.json() as UsersApiResponse | { error: string; };
|
||||
|
||||
if (res.ok && 'users' in data) {
|
||||
setUsers(data.users);
|
||||
} else {
|
||||
const errorMessage = 'error' in data ? data.error : "Unknown error";
|
||||
console.error("Failed to fetch users:", errorMessage);
|
||||
|
||||
if (errorMessage === "Admin access required") {
|
||||
setMessage("You need admin privileges to manage users.");
|
||||
} else if (errorMessage === "Not logged in") {
|
||||
setMessage("Please log in to access this page.");
|
||||
} else {
|
||||
setMessage(`Failed to load users: ${errorMessage}`);
|
||||
}
|
||||
|
||||
setUsers([]); // Set empty array to prevent undefined errors
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch users:", error);
|
||||
setMessage("Failed to load users.");
|
||||
setUsers([]); // Set empty array to prevent undefined errors
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@ -169,13 +186,22 @@ export default function UserManagementPage() {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="bg-white divide-y divide-gray-200">
|
||||
{users.length === 0 ? (
|
||||
{loading ? (
|
||||
<tr>
|
||||
<td
|
||||
colSpan={3}
|
||||
className="px-6 py-4 text-center text-sm text-gray-500"
|
||||
>
|
||||
Loading users...
|
||||
</td>
|
||||
</tr>
|
||||
) : users.length === 0 ? (
|
||||
<tr>
|
||||
<td
|
||||
colSpan={3}
|
||||
className="px-6 py-4 text-center text-sm text-gray-500"
|
||||
>
|
||||
No users found
|
||||
{message || "No users found"}
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user