- replace custom DB adapter with Drizzle setup (SQLite/Postgres schemas) and add `drizzle.config.ts` plus migrations in `drizzle/` and `drizzle_pg/` - switch better-auth to drizzleAdapter, add auth helpers (`getAuthContext`, `requireAuthContext`, `requireAudiobookOwned`), and make `useAuth`/`useAuthSession` safe no-ops when auth is disabled - persist documents/audiobooks in DB with ownership checks, unclaimed fallback, and ref-counted deletes; add FS scan helper for no-auth mode - gate docx-to-pdf, library, voices, whisper, and migration endpoints behind auth when enabled - add unclaimed data scan/claim flow with `/api/user/claim`, `ClaimDataModal`, and server-side scan/claim helpers - refactor rate limiting and account deletion to use Drizzle tables (`user_tts_chars`, `user`) - run migrations via `scripts/migrate-if-auth.mjs` (auto on `pnpm start` + `pnpm migrate`), remove Docker entrypoint and old better-auth migration file - update README and lockfile for the new migration workflow and dependencies
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { headers } from 'next/headers';
|
|
import { NextResponse } from 'next/server';
|
|
import { auth } from '@/lib/server/auth';
|
|
import { db } from '@/db';
|
|
import { user } from '@/db/schema';
|
|
import { eq } from 'drizzle-orm';
|
|
import { isAuthEnabled } from '@/lib/server/auth-config';
|
|
|
|
export async function DELETE() {
|
|
if (!isAuthEnabled() || !auth) {
|
|
return NextResponse.json({ error: 'Authentication disabled' }, { status: 403 });
|
|
}
|
|
|
|
const session = await auth.api.getSession({
|
|
headers: await headers()
|
|
});
|
|
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
try {
|
|
// Directly delete user from database
|
|
// Drizzle will handle cascade if configured in foreign keys, but typical cascading happens in DB engine
|
|
await db.delete(user).where(eq(user.id, session.user.id));
|
|
|
|
return NextResponse.json({ success: true });
|
|
} catch (error) {
|
|
console.error('Failed to delete account:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to delete account' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|