@@ -236,7 +236,10 @@ async fn create_application(req: HttpRequest, req_data: web::Json<CreateApplicat
236
236
let application_id = Uuid :: new_v4 ( ) ;
237
237
238
238
if token. is_none ( ) {
239
- return HttpResponse :: Unauthorized ( ) . body ( "" ) ;
239
+ return HttpResponse :: Unauthorized ( ) . json ( json ! ( {
240
+ "error" : "Unauthorized" ,
241
+ "message" : "Invalid token."
242
+ } ) )
240
243
}
241
244
242
245
if !req_data. permissions . iter ( ) . all ( |x| PERMISSION . contains_key ( x) ) {
@@ -358,6 +361,14 @@ async fn write_data(req: HttpRequest, req_data: web::Json<HashMap<String, Value>
358
361
#[ get( "/data/{id}" ) ]
359
362
async fn read_data ( req : HttpRequest , document_id : web:: Path < String > ) -> impl Responder {
360
363
let token = auth:: get_jwt_application_token ( req) ;
364
+
365
+ if token. is_none ( ) {
366
+ return HttpResponse :: Unauthorized ( ) . json ( json ! ( {
367
+ "error" : "Unauthorized" ,
368
+ "message" : "Invalid token. Please use JWT token for application, not your admin token"
369
+ } ) ) ;
370
+ }
371
+
361
372
let database = DATABASE_CLIENT
362
373
. lock ( )
363
374
. unwrap ( ) ;
@@ -434,6 +445,14 @@ async fn read_data(req: HttpRequest, document_id: web::Path<String>) -> impl Res
434
445
#[ delete( "/data/{id}" ) ]
435
446
async fn delete_data ( req : HttpRequest , document_id : web:: Path < String > ) -> impl Responder {
436
447
let token = auth:: get_jwt_application_token ( req) ;
448
+
449
+ if token. is_none ( ) {
450
+ return HttpResponse :: Unauthorized ( ) . json ( json ! ( {
451
+ "error" : "Unauthorized" ,
452
+ "message" : "Invalid token. Please use JWT token for application, not your admin token"
453
+ } ) ) ;
454
+ }
455
+
437
456
let document_id = document_id. to_string ( ) ;
438
457
439
458
if Uuid :: try_parse ( & document_id) . is_err ( ) {
@@ -513,6 +532,14 @@ async fn delete_data(req: HttpRequest, document_id: web::Path<String>) -> impl R
513
532
#[ put( "/data/{id}" ) ]
514
533
async fn update_data ( req : HttpRequest , document_id : web:: Path < String > , req_data : web:: Json < Document > ) -> impl Responder {
515
534
let token = auth:: get_jwt_application_token ( req) ;
535
+
536
+ if token. is_none ( ) {
537
+ return HttpResponse :: Unauthorized ( ) . json ( json ! ( {
538
+ "error" : "Unauthorized" ,
539
+ "message" : "Invalid token. Please use JWT token for application, not your admin token"
540
+ } ) ) ;
541
+ }
542
+
516
543
let document_id = document_id. to_string ( ) ;
517
544
518
545
if Uuid :: try_parse ( & document_id) . is_err ( ) {
0 commit comments