rupadana / filament-api-service

A simple api service for supporting filamentphp
https://filamentphp.com/plugins/rupadana-api-service
MIT License
95 stars 23 forks source link

[Bug]: Not able to get the records from api #58

Open jaskaran-online opened 3 weeks ago

jaskaran-online commented 3 weeks ago

What happened?

localhost:8000/api/products

i have create Product api service using following command
php artisan make:filament-api-service ProductResource

Route List

image

Postman

image

How to reproduce the bug

its showing routes on artisan route:list but when try to access using postman getting error config fie image

Package Version

3.2.4

PHP Version

8.3

Laravel Version

10.10

Which operating systems does with happen with?

Windows

Notes

No response

eelco2k commented 3 weeks ago

@jaskaran-online this is probably because your authentication is not correctly setup and therefor in middleware Http/Middleware/Authenticate.php you are being redirected to /login (route('login'). except Filament does not have that url by default. as your panel is probably at /admin/login. Please check auth (bearer token). Because middleware Auth is failing.

or disable auth for that resource see: https://filamentphp.com/plugins/rupadana-api-service#public-api

eelco2k commented 3 weeks ago

you could try changing this behaviour by using:

return $request->expectsJson() ? null : Filament::getCurrentPanel()?->getLoginUrl();

then at least you will get redirected to the filament login url and not get laravel error

jazzy1986 commented 3 weeks ago

facing the same problem image

jazzy1986 commented 3 weeks ago

@jaskaran-online this is probably because your authentication is not correctly setup and therefor in middleware Http/Middleware/Authenticate.php you are being redirected to /login (route('login'). except Filament does not have that url by default. as your panel is probably at /admin/login. Please check auth (bearer token). Because middleware Auth is failing.

or disable auth for that resource see: https://filamentphp.com/plugins/rupadana-api-service#public-api

rather don't want to set it as public api if possible.

eelco2k commented 3 weeks ago

Then you have to make sure you setup sanctum authentication correctly. Create a token with correct abilities. And use that token as your bearer http header.