Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(api): set userEmail for API key auth and document public routes

Tinfedd40a06573
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index e5623fa97..86e27663f 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -132,20 +132,57 @@ export function createApp() {
return c.json({ status: "ok" });
});
- const publicProjectApi = api.get("/public-project/:id", async (c) => {
- const { id } = c.req.param();
- const project = await getPublicProject(id);
+ const publicProjectApi = api.get(
+ "/public-project/:id",
+ describeRoute({
+ operationId: "getPublicProject",
+ tags: ["Projects"],
+ description: "Get a public project by ID (no authentication required)",
+ security: [],
+ responses: {
+ 200: {
+ description: "Public project details",
+ content: {
+ "application/json": { schema: resolver(v.any()) },
+ },
+ },
+ },
+ }),
+ validator("param", v.object({ id: v.string() })),
+ async (c) => {
+ const { id } = c.req.valid("param");
+ const project = await getPublicProject(id);
- return c.json(project);
- });
+ return c.json(project);
+ },
+ );
api.post("/github-integration/webhook", handleGithubWebhookRoute);
- const invitationPublicApi = api.get("/invitation/public/:id", async (c) => {
- const { id } = c.req.param();
- const result = await getInvitationDetails(id);
- return c.json(result);
- });
+ const invitationPublicApi = api.get(
+ "/invitation/public/:id",
+ describeRoute({
+ operationId: "getPublicInvitationDetails",
+ tags: ["Invitations"],
+ description:
+ "Get invitation details by token ID (no authentication required)",
+ security: [],
+ responses: {
+ 200: {
+ description: "Invitation details for the public link",
+ content: {
+ "application/json": { schema: resolver(v.any()) },
+ },
+ },
+ },
+ }),
+ validator("param", v.object({ id: v.string() })),
+ async (c) => {
+ const { id } = c.req.valid("param");
+ const result = await getInvitationDetails(id);
+ return c.json(result);
+ },
+ );
api.get(
"/auth/get-session",
@@ -355,7 +392,8 @@ export function createApp() {
const result = await verifyApiKey(apiKey);
if (result?.valid && result.key) {
- c.set("userId", result.key.userId);
+ const userId = result.key.userId;
+ c.set("userId", userId);
c.set("user", null);
c.set("session", null);
c.set("apiKey", {
@@ -363,6 +401,14 @@ export function createApp() {
userId: result.key.userId,
enabled: result.key.enabled,
});
+
+ const [userRow] = await db
+ .select({ email: schema.userTable.email })
+ .from(schema.userTable)
+ .where(eq(schema.userTable.id, userId))
+ .limit(1);
+ c.set("userEmail", userRow?.email ?? "");
+
return next();
}
diff --git a/apps/api/src/project/controllers/create-project.ts b/apps/api/src/project/controllers/create-project.ts
index b1acd8048..3d91db7cb 100644
--- a/apps/api/src/project/controllers/create-project.ts
+++ b/apps/api/src/project/controllers/create-project.ts
@@ -1,12 +1,12 @@
import db from "../../database";
import { columnTable, projectTable } from "../../database/schema";
-const DEFAULT_COLUMNS = [
+export const DEFAULT_PROJECT_COLUMNS = [
{ name: "To Do", slug: "to-do", position: 0, isFinal: false },
{ name: "In Progress", slug: "in-progress", position: 1, isFinal: false },
{ name: "In Review", slug: "in-review", position: 2, isFinal: false },
{ name: "Done", slug: "done", position: 3, isFinal: true },
-];
+] as const;
async function createProject(
workspaceId: string,
@@ -25,7 +25,7 @@ async function createProject(
.returning();
if (createdProject) {
- for (const col of DEFAULT_COLUMNS) {
+ for (const col of DEFAULT_PROJECT_COLUMNS) {
await db.insert(columnTable).values({
projectId: createdProject.id,
name: col.name,