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

@ -4,13 +4,13 @@
* Usage: node scripts/d1.js <command> [args...]
*/
import { execSync } from 'child_process';
import { execSync } from "child_process";
const DB_NAME = 'd1-notso-livedash';
const DB_NAME = "d1-notso-livedash";
const args = process.argv.slice(2);
if (args.length === 0) {
console.log(`
console.log(`
🗄️ Simple D1 CLI for ${DB_NAME}
Usage: node scripts/d1.js <command> [args...]
@ -31,59 +31,66 @@ Examples:
node scripts/d1.js query "SELECT COUNT(*) FROM Company"
node scripts/d1.js --remote info
`);
process.exit(0);
process.exit(0);
}
const isRemote = args.includes('--remote');
const filteredArgs = args.filter(arg => !arg.startsWith('--'));
const [ command, ...params ] = filteredArgs;
const remoteFlag = isRemote ? '--remote' : '';
const isRemote = args.includes("--remote");
const filteredArgs = args.filter((arg) => !arg.startsWith("--"));
const [command, ...params] = filteredArgs;
const remoteFlag = isRemote ? "--remote" : "";
function run(cmd) {
try {
console.log(`💫 ${cmd}`);
execSync(cmd, { stdio: 'inherit' });
} catch (error) {
console.error('❌ Command failed');
process.exit(1);
}
try {
console.log(`💫 ${cmd}`);
execSync(cmd, { stdio: "inherit" });
} catch (error) {
console.error("❌ Command failed");
process.exit(1);
}
}
switch (command) {
case 'list':
run('npx wrangler d1 list');
break;
case "list":
run("npx wrangler d1 list");
break;
case 'info':
run(`npx wrangler d1 info ${DB_NAME} ${remoteFlag}`);
break;
case "info":
run(`npx wrangler d1 info ${DB_NAME} ${remoteFlag}`);
break;
case 'tables':
run(`npx wrangler d1 execute ${DB_NAME} ${remoteFlag} --command "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"`);
break;
case "tables":
run(
`npx wrangler d1 execute ${DB_NAME} ${remoteFlag} --command "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"`
);
break;
case 'schema':
if (!params[ 0 ]) {
console.error('❌ Please specify table name');
process.exit(1);
}
run(`npx wrangler d1 execute ${DB_NAME} ${remoteFlag} --command "PRAGMA table_info(${params[ 0 ]})"`);
break;
case "schema":
if (!params[0]) {
console.error("❌ Please specify table name");
process.exit(1);
}
run(
`npx wrangler d1 execute ${DB_NAME} ${remoteFlag} --command "PRAGMA table_info(${params[0]})"`
);
break;
case 'query':
if (!params[ 0 ]) {
console.error('❌ Please specify SQL query');
process.exit(1);
}
run(`npx wrangler d1 execute ${DB_NAME} ${remoteFlag} --command "${params[ 0 ]}"`);
break;
case "query":
if (!params[0]) {
console.error("❌ Please specify SQL query");
process.exit(1);
}
run(
`npx wrangler d1 execute ${DB_NAME} ${remoteFlag} --command "${params[0]}"`
);
break;
case 'export':
const filename = params[ 0 ] || `backup_${new Date().toISOString().slice(0, 10)}.sql`;
run(`npx wrangler d1 export ${DB_NAME} ${remoteFlag} --output ${filename}`);
break;
case "export":
const filename =
params[0] || `backup_${new Date().toISOString().slice(0, 10)}.sql`;
run(`npx wrangler d1 export ${DB_NAME} ${remoteFlag} --output ${filename}`);
break;
default:
console.error(`❌ Unknown command: ${command}`);
process.exit(1);
default:
console.error(`❌ Unknown command: ${command}`);
process.exit(1);
}