mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 13:12: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.
36 lines
1021 B
TypeScript
36 lines
1021 B
TypeScript
// API endpoint: update company CSV URL config
|
|
import { NextApiRequest, NextApiResponse } from "next";
|
|
import { getApiSession } from "../../../lib/api-auth";
|
|
import { prisma } from "../../../lib/prisma";
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse
|
|
) {
|
|
const session = await getApiSession(req, res);
|
|
if (!session?.user) return res.status(401).json({ error: "Not logged in" });
|
|
|
|
const user = await prisma.user.findUnique({
|
|
where: { email: session.user.email as string },
|
|
});
|
|
|
|
if (!user) return res.status(401).json({ error: "No user" });
|
|
|
|
if (req.method === "POST") {
|
|
const { csvUrl } = req.body;
|
|
await prisma.company.update({
|
|
where: { id: user.companyId },
|
|
data: { csvUrl },
|
|
});
|
|
res.json({ ok: true });
|
|
} else if (req.method === "GET") {
|
|
// Get company data
|
|
const company = await prisma.company.findUnique({
|
|
where: { id: user.companyId },
|
|
});
|
|
res.json({ company });
|
|
} else {
|
|
res.status(405).end();
|
|
}
|
|
}
|