From 0f71175ad899337b7a557dd0bb47d8e7c56c470c Mon Sep 17 00:00:00 2001 From: I Wayan Rupadana Date: Fri, 9 Feb 2024 21:23:38 +0800 Subject: [PATCH 1/3] public api --- routes/api.php | 1 - src/Commands/MakeApiServiceCommand.php | 2 +- src/Http/Handlers.php | 19 ++++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/routes/api.php b/routes/api.php index a299907..801c224 100644 --- a/routes/api.php +++ b/routes/api.php @@ -5,7 +5,6 @@ Route::prefix('api') ->name('api.') - ->middleware('auth:sanctum') ->group(function () { $panels = Filament::getPanels(); diff --git a/src/Commands/MakeApiServiceCommand.php b/src/Commands/MakeApiServiceCommand.php index 880495b..f241eb8 100644 --- a/src/Commands/MakeApiServiceCommand.php +++ b/src/Commands/MakeApiServiceCommand.php @@ -143,7 +143,7 @@ public function handle(): int ]); $this->components->info("Successfully created API for {$resource}!"); - $this->components->info("It automatically registered to '/api-service' route group"); + $this->components->info("It automatically registered to '/api' route group"); return static::SUCCESS; } diff --git a/src/Http/Handlers.php b/src/Http/Handlers.php index 87b10f3..9ad9c82 100644 --- a/src/Http/Handlers.php +++ b/src/Http/Handlers.php @@ -18,6 +18,8 @@ class Handlers protected static string $keyName = 'id'; + protected static bool $public = false; + const POST = 'post'; const GET = 'get'; @@ -40,7 +42,22 @@ public static function route(Router $router) $router ->$method(static::$uri, [static::class, 'handler']) ->name(static::getKebabClassName()) - ->middleware(static::getMiddlewareAliasName().':'.static::stringifyAbility()); + ->middleware(static::getRouteMiddleware()); + } + + public static function isPublic() : bool + { + return static::$public; + } + + public static function getRouteMiddleware() : array + { + if(static::isPublic()) return []; + + return [ + 'auth:sanctum', + static::getMiddlewareAliasName() . ':' . static::stringifyAbility() + ]; } protected static function getMiddlewareAliasName() From 828f4303fc577a0d40c05f92eee7a7d8d2236223 Mon Sep 17 00:00:00 2001 From: rupadana Date: Fri, 9 Feb 2024 13:24:09 +0000 Subject: [PATCH 2/3] Fix styling --- src/Http/Handlers.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Http/Handlers.php b/src/Http/Handlers.php index 9ad9c82..7b460f4 100644 --- a/src/Http/Handlers.php +++ b/src/Http/Handlers.php @@ -45,18 +45,20 @@ public static function route(Router $router) ->middleware(static::getRouteMiddleware()); } - public static function isPublic() : bool + public static function isPublic(): bool { return static::$public; } - public static function getRouteMiddleware() : array + public static function getRouteMiddleware(): array { - if(static::isPublic()) return []; + if (static::isPublic()) { + return []; + } return [ 'auth:sanctum', - static::getMiddlewareAliasName() . ':' . static::stringifyAbility() + static::getMiddlewareAliasName().':'.static::stringifyAbility(), ]; } From e3040ca821e617935e17786ccc80efb8fb537dc5 Mon Sep 17 00:00:00 2001 From: I Wayan Rupadana Date: Fri, 9 Feb 2024 21:34:16 +0800 Subject: [PATCH 3/3] update readme --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 3996827..328539b 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,16 @@ To Generate Token, you just need create it from admin panel. It will be Token Re ![Image](https://res.cloudinary.com/rupadana/image/upload/v1704958748/Screenshot_2024-01-11_at_15.37.55_ncpg8n.png) +## Public API + +Set API to public by overriding this property on your API Handler. Assume we have a `PaginationHandler` + +```php +class PaginationHandler extends Handlers { + public static bool $public = true; +} +``` + ## TODO - [ ] Test Plugin for Tenancy purpose