@@ -44,7 +44,25 @@ export class OBPController {
4444 async get ( @Session ( ) session : any , @Req ( ) request : Request , @Res ( ) response : Response ) : Response {
4545 const path = request . query . path
4646 const oauthConfig = session [ 'clientConfig' ]
47- return response . json ( await this . obpClientService . get ( path , oauthConfig ) )
47+
48+ // Check if user is authenticated
49+ if ( ! oauthConfig || ! oauthConfig . oauth2 ?. accessToken ) {
50+ return response . status ( 401 ) . json ( {
51+ code : 401 ,
52+ message : 'OBP-20001: User not logged in. Authentication is required!'
53+ } )
54+ }
55+
56+ try {
57+ const result = await this . obpClientService . get ( path , oauthConfig )
58+ return response . json ( result )
59+ } catch ( error : any ) {
60+ console . error ( 'RequestController.get error:' , error )
61+ return response . status ( error . status || 500 ) . json ( {
62+ code : error . status || 500 ,
63+ message : error . message || 'Internal server error'
64+ } )
65+ }
4866 }
4967
5068 @Post ( '/create' )
@@ -56,7 +74,25 @@ export class OBPController {
5674 const path = request . query . path
5775 const data = request . body
5876 const oauthConfig = session [ 'clientConfig' ]
59- return response . json ( await this . obpClientService . create ( path , data , oauthConfig ) )
77+
78+ // Check if user is authenticated
79+ if ( ! oauthConfig || ! oauthConfig . oauth2 ?. accessToken ) {
80+ return response . status ( 401 ) . json ( {
81+ code : 401 ,
82+ message : 'OBP-20001: User not logged in. Authentication is required!'
83+ } )
84+ }
85+
86+ try {
87+ const result = await this . obpClientService . create ( path , data , oauthConfig )
88+ return response . json ( result )
89+ } catch ( error : any ) {
90+ console . error ( 'RequestController.create error:' , error )
91+ return response . status ( error . status || 500 ) . json ( {
92+ code : error . status || 500 ,
93+ message : error . message || 'Internal server error'
94+ } )
95+ }
6096 }
6197
6298 @Put ( '/update' )
@@ -68,7 +104,25 @@ export class OBPController {
68104 const path = request . query . path
69105 const data = request . body
70106 const oauthConfig = session [ 'clientConfig' ]
71- return response . json ( await this . obpClientService . update ( path , data , oauthConfig ) )
107+
108+ // Check if user is authenticated
109+ if ( ! oauthConfig || ! oauthConfig . oauth2 ?. accessToken ) {
110+ return response . status ( 401 ) . json ( {
111+ code : 401 ,
112+ message : 'OBP-20001: User not logged in. Authentication is required!'
113+ } )
114+ }
115+
116+ try {
117+ const result = await this . obpClientService . update ( path , data , oauthConfig )
118+ return response . json ( result )
119+ } catch ( error : any ) {
120+ console . error ( 'RequestController.update error:' , error )
121+ return response . status ( error . status || 500 ) . json ( {
122+ code : error . status || 500 ,
123+ message : error . message || 'Internal server error'
124+ } )
125+ }
72126 }
73127
74128 @Delete ( '/delete' )
@@ -79,6 +133,24 @@ export class OBPController {
79133 ) : Response {
80134 const path = request . query . path
81135 const oauthConfig = session [ 'clientConfig' ]
82- return response . json ( await this . obpClientService . discard ( path , oauthConfig ) )
136+
137+ // Check if user is authenticated
138+ if ( ! oauthConfig || ! oauthConfig . oauth2 ?. accessToken ) {
139+ return response . status ( 401 ) . json ( {
140+ code : 401 ,
141+ message : 'OBP-20001: User not logged in. Authentication is required!'
142+ } )
143+ }
144+
145+ try {
146+ const result = await this . obpClientService . discard ( path , oauthConfig )
147+ return response . json ( result )
148+ } catch ( error : any ) {
149+ console . error ( 'RequestController.delete error:' , error )
150+ return response . status ( error . status || 500 ) . json ( {
151+ code : error . status || 500 ,
152+ message : error . message || 'Internal server error'
153+ } )
154+ }
83155 }
84156}
0 commit comments