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:
2025-06-01 16:34:54 +02:00
parent 71c8aff125
commit bde0b44ea0
53 changed files with 20841 additions and 6435 deletions

View File

@ -18,8 +18,8 @@ import ResponseTimeDistribution from "../../../components/ResponseTimeDistributi
import WelcomeBanner from "../../../components/WelcomeBanner";
interface MetricsApiResponse {
metrics: MetricsResult;
company: Company;
metrics: MetricsResult;
company: Company;
}
// Safely wrapped component with useSession
@ -45,7 +45,7 @@ function DashboardContent() {
const fetchData = async () => {
setLoading(true);
const res = await fetch("/api/dashboard/metrics");
const data = (await res.json()) as MetricsApiResponse;
const data = (await res.json()) as MetricsApiResponse;
console.log("Metrics from API:", {
avgSessionLength: data.metrics.avgSessionLength,
avgSessionTimeTrend: data.metrics.avgSessionTimeTrend,
@ -81,10 +81,10 @@ function DashboardContent() {
if (res.ok) {
// Refetch metrics
const metricsRes = await fetch("/api/dashboard/metrics");
const data = (await metricsRes.json()) as MetricsApiResponse;
const data = (await metricsRes.json()) as MetricsApiResponse;
setMetrics(data.metrics);
} else {
const errorData = (await res.json()) as { error: string; };
const errorData = (await res.json()) as { error: string };
alert(`Failed to refresh sessions: ${errorData.error}`);
}
} finally {