mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 15:32:10 +01:00
- 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.
34 lines
963 B
TypeScript
34 lines
963 B
TypeScript
// Prisma client setup with support for Cloudflare D1
|
|
import { PrismaClient } from "@prisma/client";
|
|
import { PrismaD1 } from "@prisma/adapter-d1";
|
|
|
|
// Add prisma to the NodeJS global type
|
|
// This approach avoids NodeJS.Global which is not available
|
|
|
|
// Prevent multiple instances of Prisma Client in development
|
|
declare const global: {
|
|
prisma: PrismaClient | undefined;
|
|
};
|
|
|
|
// Check if we're running in Cloudflare Workers environment
|
|
const isCloudflareWorker = typeof globalThis.DB !== "undefined";
|
|
|
|
// Initialize Prisma Client
|
|
let prisma: PrismaClient;
|
|
|
|
if (isCloudflareWorker) {
|
|
// In Cloudflare Workers, use D1 adapter
|
|
const adapter = new PrismaD1(globalThis.DB);
|
|
prisma = new PrismaClient({ adapter });
|
|
} else {
|
|
// In Next.js/Node.js, use regular SQLite
|
|
prisma = global.prisma || new PrismaClient();
|
|
|
|
// Save in global if we're in development
|
|
if (process.env.NODE_ENV !== "production") {
|
|
global.prisma = prisma;
|
|
}
|
|
}
|
|
|
|
export { prisma };
|