File tree Expand file tree Collapse file tree 8 files changed +20
-78
lines changed
Expand file tree Collapse file tree 8 files changed +20
-78
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff line change @@ -2,15 +2,15 @@ import { eq } from "drizzle-orm";
22import { Elysia } from "elysia" ;
33import { db } from "../../db/index.ts" ;
44import { organizationMembers , organizations } from "../../db/schema.ts" ;
5- import type { AuthUser } from "../../middleware/auth.ts" ;
5+ import { authMiddleware } from "../../middleware/auth.ts" ;
66import { 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" } ;
Original file line number Diff line number Diff line change @@ -2,25 +2,17 @@ import { eq } from "drizzle-orm";
22import { Elysia , t } from "elysia" ;
33import { db } from "../../db/index.ts" ;
44import { organizationMembers , organizations } from "../../db/schema.ts" ;
5- import type { AuthUser } from "../../middleware/auth.ts" ;
5+ import { authMiddleware } from "../../middleware/auth.ts" ;
66import { 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" } ;
Original file line number Diff line number Diff line change @@ -2,30 +2,16 @@ import { and, eq } from "drizzle-orm";
22import { Elysia , t } from "elysia" ;
33import { db } from "../../db/index.ts" ;
44import { organizationMembers , users } from "../../db/schema.ts" ;
5- import type { AuthUser } from "../../middleware/auth.ts" ;
5+ import { authMiddleware } from "../../middleware/auth.ts" ;
66import { 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" } ;
Original file line number Diff line number Diff line change @@ -2,24 +2,16 @@ import { eq } from "drizzle-orm";
22import { Elysia } from "elysia" ;
33import { db } from "../../db/index.ts" ;
44import { organizationMembers , users } from "../../db/schema.ts" ;
5- import type { AuthUser } from "../../middleware/auth.ts" ;
5+ import { authMiddleware } from "../../middleware/auth.ts" ;
66import { 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" } ;
Original file line number Diff line number Diff line change @@ -2,24 +2,16 @@ import { and, eq } from "drizzle-orm";
22import { Elysia } from "elysia" ;
33import { db } from "../../db/index.ts" ;
44import { organizationMembers } from "../../db/schema.ts" ;
5- import type { AuthUser } from "../../middleware/auth.ts" ;
5+ import { authMiddleware } from "../../middleware/auth.ts" ;
66import { 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" } ;
Original file line number Diff line number Diff line change 11import { Elysia } from "elysia" ;
2- import { authMiddleware } from "../../middleware/auth.ts" ;
32import { organizationReadRoutes } from "./crud-read.ts" ;
43import { organizationWriteRoutes } from "./crud-write.ts" ;
54import { 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 */
1312export const organizationRoutes = new Elysia ( { prefix : "/organizations" } )
14- . use ( authMiddleware )
1513 . use ( organizationReadRoutes )
1614 . use ( organizationWriteRoutes )
1715 . use ( organizationMemberReadRoutes )
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ if (!jwtSecret) {
1515export 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 } ;
You can’t perform that action at this time.
0 commit comments