Skip to content

Commit 139d48d

Browse files
aster-voidclaude
andcommitted
server: fix all TypeScript and linter errors
- Remove all `any` types from organization routes by leveraging Elysia type inference and adding authMiddleware to route files - Add optional chaining for cookie.token access to handle undefined cases - Remove explicit type annotations where TypeScript can infer correctly All TypeScript errors and biome lint warnings are now resolved. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent 1f416f5 commit 139d48d

File tree

8 files changed

+20
-78
lines changed

8 files changed

+20
-78
lines changed

apps/server/src/domains/auth/routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const authRoutes = new Elysia({ prefix: "/auth" })
4545
});
4646

4747
// Set cookie
48-
cookie.token.set({
48+
cookie.token?.set({
4949
value: token,
5050
httpOnly: true,
5151
maxAge: 7 * 24 * 60 * 60, // 7 days
@@ -61,7 +61,7 @@ export const authRoutes = new Elysia({ prefix: "/auth" })
6161
},
6262
)
6363
.post("/signout", async ({ cookie }) => {
64-
cookie.token.set({
64+
cookie.token?.set({
6565
value: "",
6666
httpOnly: true,
6767
maxAge: 0,

apps/server/src/domains/organizations/crud-read.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { eq } from "drizzle-orm";
22
import { Elysia } from "elysia";
33
import { db } from "../../db/index.ts";
44
import { organizationMembers, organizations } from "../../db/schema.ts";
5-
import type { AuthUser } from "../../middleware/auth.ts";
5+
import { authMiddleware } from "../../middleware/auth.ts";
66
import { getOrganizationPermissions } from "./permissions.ts";
77

88
/**
99
* Organization read routes
1010
* Handles: list organizations, get organization by ID
1111
*/
12-
export const organizationReadRoutes = new Elysia()
13-
.get("/", async ({ user, set }: { user: AuthUser | null; set: any }) => {
12+
export const organizationReadRoutes = new Elysia().use(authMiddleware)
13+
.get("/", async ({ user, set }) => {
1414
if (!user) {
1515
set.status = 401;
1616
return { message: "Unauthorized" };
@@ -36,15 +36,7 @@ export const organizationReadRoutes = new Elysia()
3636
})
3737
.get(
3838
"/:id",
39-
async ({
40-
user,
41-
params,
42-
set,
43-
}: {
44-
user: AuthUser | null;
45-
params: { id: string };
46-
set: any;
47-
}) => {
39+
async ({ user, params, set }) => {
4840
if (!user) {
4941
set.status = 401;
5042
return { message: "Unauthorized" };

apps/server/src/domains/organizations/crud-write.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,17 @@ import { eq } from "drizzle-orm";
22
import { Elysia, t } from "elysia";
33
import { db } from "../../db/index.ts";
44
import { organizationMembers, organizations } from "../../db/schema.ts";
5-
import type { AuthUser } from "../../middleware/auth.ts";
5+
import { authMiddleware } from "../../middleware/auth.ts";
66
import { getOrganizationPermissions } from "./permissions.ts";
77

88
/**
99
* Organization write routes
1010
* Handles: create organization, update organization
1111
*/
12-
export const organizationWriteRoutes = new Elysia()
12+
export const organizationWriteRoutes = new Elysia().use(authMiddleware)
1313
.post(
1414
"/",
15-
async ({
16-
user,
17-
body,
18-
set,
19-
}: {
20-
user: AuthUser | null;
21-
body: { name: string; description?: string };
22-
set: any;
23-
}) => {
15+
async ({ user, body, set }) => {
2416
if (!user) {
2517
set.status = 401;
2618
return { message: "Unauthorized" };
@@ -54,17 +46,7 @@ export const organizationWriteRoutes = new Elysia()
5446
)
5547
.patch(
5648
"/:id",
57-
async ({
58-
user,
59-
body,
60-
params,
61-
set,
62-
}: {
63-
user: AuthUser | null;
64-
body: { name?: string; description?: string };
65-
params: { id: string };
66-
set: any;
67-
}) => {
49+
async ({ user, body, params, set }) => {
6850
if (!user) {
6951
set.status = 401;
7052
return { message: "Unauthorized" };

apps/server/src/domains/organizations/members-add.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,16 @@ import { and, eq } from "drizzle-orm";
22
import { Elysia, t } from "elysia";
33
import { db } from "../../db/index.ts";
44
import { organizationMembers, users } from "../../db/schema.ts";
5-
import type { AuthUser } from "../../middleware/auth.ts";
5+
import { authMiddleware } from "../../middleware/auth.ts";
66
import { getOrganizationPermissions } from "./permissions.ts";
77

88
/**
99
* Organization member addition route
1010
* Handles: add member to organization
1111
*/
12-
export const organizationMemberAddRoute = new Elysia().post(
12+
export const organizationMemberAddRoute = new Elysia().use(authMiddleware).post(
1313
"/:id/members",
14-
async ({
15-
user,
16-
body,
17-
params,
18-
set,
19-
}: {
20-
user: AuthUser | null;
21-
body: {
22-
userId: string;
23-
role?: string;
24-
permission: "admin" | "member" | "visitor";
25-
};
26-
params: { id: string };
27-
set: any;
28-
}) => {
14+
async ({ user, body, params, set }) => {
2915
if (!user) {
3016
set.status = 401;
3117
return { message: "Unauthorized" };

apps/server/src/domains/organizations/members-read.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,16 @@ import { eq } from "drizzle-orm";
22
import { Elysia } from "elysia";
33
import { db } from "../../db/index.ts";
44
import { organizationMembers, users } from "../../db/schema.ts";
5-
import type { AuthUser } from "../../middleware/auth.ts";
5+
import { authMiddleware } from "../../middleware/auth.ts";
66
import { getOrganizationPermissions } from "./permissions.ts";
77

88
/**
99
* Organization member read routes
1010
* Handles: list members
1111
*/
12-
export const organizationMemberReadRoutes = new Elysia().get(
12+
export const organizationMemberReadRoutes = new Elysia().use(authMiddleware).get(
1313
"/:id/members",
14-
async ({
15-
user,
16-
params,
17-
set,
18-
}: {
19-
user: AuthUser | null;
20-
params: { id: string };
21-
set: any;
22-
}) => {
14+
async ({ user, params, set }) => {
2315
if (!user) {
2416
set.status = 401;
2517
return { message: "Unauthorized" };

apps/server/src/domains/organizations/members-remove.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,16 @@ import { and, eq } from "drizzle-orm";
22
import { Elysia } from "elysia";
33
import { db } from "../../db/index.ts";
44
import { organizationMembers } from "../../db/schema.ts";
5-
import type { AuthUser } from "../../middleware/auth.ts";
5+
import { authMiddleware } from "../../middleware/auth.ts";
66
import { getOrganizationPermissions } from "./permissions.ts";
77

88
/**
99
* Organization member removal route
1010
* Handles: remove member from organization
1111
*/
12-
export const organizationMemberRemoveRoute = new Elysia().delete(
12+
export const organizationMemberRemoveRoute = new Elysia().use(authMiddleware).delete(
1313
"/:id/members/:userId",
14-
async ({
15-
user,
16-
params,
17-
set,
18-
}: {
19-
user: AuthUser | null;
20-
params: { id: string; userId: string };
21-
set: any;
22-
}) => {
14+
async ({ user, params, set }) => {
2315
if (!user) {
2416
set.status = 401;
2517
return { message: "Unauthorized" };

apps/server/src/domains/organizations/routes.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Elysia } from "elysia";
2-
import { authMiddleware } from "../../middleware/auth.ts";
32
import { organizationReadRoutes } from "./crud-read.ts";
43
import { organizationWriteRoutes } from "./crud-write.ts";
54
import { organizationMemberAddRoute } from "./members-add.ts";
@@ -11,7 +10,6 @@ import { organizationMemberRemoveRoute } from "./members-remove.ts";
1110
* Combines CRUD and member management routes under /organizations prefix
1211
*/
1312
export const organizationRoutes = new Elysia({ prefix: "/organizations" })
14-
.use(authMiddleware)
1513
.use(organizationReadRoutes)
1614
.use(organizationWriteRoutes)
1715
.use(organizationMemberReadRoutes)

apps/server/src/middleware/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (!jwtSecret) {
1515
export const authMiddleware = new Elysia({ name: "auth" })
1616
.use(jwt({ name: "jwt", secret: jwtSecret }))
1717
.derive({ as: "global" }, async ({ jwt, cookie }) => {
18-
const tokenValue = cookie.token.value;
18+
const tokenValue = cookie.token?.value;
1919

2020
if (!tokenValue || typeof tokenValue !== "string") {
2121
return { user: null as AuthUser | null };

0 commit comments

Comments
 (0)