Stitch
Stitch
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
Makes sense, glad to hear you say that and are on the same page as I've been debating rearranging everything for the last hour to intergrate sanctum aha
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
I guess if I used Sanctum for both, it would avoid using multiple authentication methods to
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
Hey nice, that's interesting. What approach would you use personally do you think, if you were to have a public API and have the user accessible site. Sanctum is looking like the best way to handle both tokens for logged in user sessions on the site and API tokens for the public API for each user
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
It is currently working fine, but from learning laravel atm it seems best to pull the user_id from the controller, but if you think livewire is a better way I'd like to hear it
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
This is the Test API button using Filament actions I made in app/Filament/Pages/Orders.php
protected function getHeaderActions(): array
{
return [
Actions\Action::make('testApiCall')
->label('Test API Call')
->action(function () {
// Log the request sent to the controller
Log::info('Request sent to the controller', [
'service' => $this->service,
'country' => $this->country,
'operator' => $this->operator,
'user_id' => Auth::id(),
]);

$response = Http::post('https://sms.ddev.site/api/orders/new', [
'service' => 'Netflix',
'country' => 'United Kingdom',
'operator' => 'Vodafone',
'user_id' => Auth::id(), // Pass the authenticated user's ID
]);

if ($response->successful()) {
Notification::make()
->title('API call successful.')
->success()
->send();
} else {
Notification::make()
->title('API call failed.')
->danger()
->send();
}
}),
];
}
protected function getHeaderActions(): array
{
return [
Actions\Action::make('testApiCall')
->label('Test API Call')
->action(function () {
// Log the request sent to the controller
Log::info('Request sent to the controller', [
'service' => $this->service,
'country' => $this->country,
'operator' => $this->operator,
'user_id' => Auth::id(),
]);

$response = Http::post('https://sms.ddev.site/api/orders/new', [
'service' => 'Netflix',
'country' => 'United Kingdom',
'operator' => 'Vodafone',
'user_id' => Auth::id(), // Pass the authenticated user's ID
]);

if ($response->successful()) {
Notification::make()
->title('API call successful.')
->success()
->send();
} else {
Notification::make()
->title('API call failed.')
->danger()
->send();
}
}),
];
}
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
Ah, I thought all livewire file types were stored in views/livewire and were blade files though?
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
Inside Filament in the Pages folder, and if the Orders.php from the page folder is able to now pull the user_id, I don't see why I shouldn't be able to get the controller to do it instead. Currently looking into livewire though if you think that's a better approach
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
Tokens might be the way to go since each user will be having their own API token anyway to access the public API the service I'm building will have. I was looking to integrate this once I had the order controller built https://github.com/jeffgreco13/filament-breezy to make it easy to integrate the necessary features. Do you think it's worth integrating it now so that I can switch the whole authentication system over to sanctum for both the site and the public API? Also I'm quite new to Laravel and have only just mostly got my head around using controllers etc, haven't really got around to learning livewire yet
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
I think this may have been the fix, now it seems to be passing the user_id from app/Fillament/Pages/Orders.php to the controller according to the logging. Ideally it's more secure to pull the user_id in the controller though instead of the fillament page passing it to the controller though right? And yes I'm also using Laravel 11, thank you for your help so far with this
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
I tried inserting /sMS/login and that didn't work either
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
<?php use Illuminate\Support\Facades\Route; Route::redirect('/login', '/admin/login')->name('login');
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
ddev php artisan route:list ─╯ POST _ignition/execute-solution ignition.executeSolution › Spatie… GET|HEAD _ignition/health-check ignition.healthCheck › Spatie\LaravelI… POST _ignition/update-config ignition.updateConfig › Spatie\Larave… POST api/orders/new ..................... UserOrderController@store GET|HEAD api/user ..................................................... GET|HEAD filament/exports/{export}/download filament.exports.download … GET|HEAD filament/imports/{import}/failed-rows/download filament.impor… GET|HEAD livewire/livewire.js Livewire\Mechanisms › FrontendAssets@ret… GET|HEAD livewire/livewire.min.js.map Livewire\Mechanisms › FrontendAs… GET|HEAD livewire/preview-file/{filename} livewire.preview-file › Live… POST livewire/update livewire.update › Livewire\Mechanisms › Handl… POST livewire/upload-file livewire.upload-file › Livewire\Features… ANY login ........ login › Illuminate\Routing › RedirectController GET|HEAD sMS filament.sMS.pages.dashboard › Filament\Pages › Dashboard GET|HEAD sMS/deposits-page filament.sMS.pages.deposits-page › App\Fila… GET|HEAD sMS/login ... filament.sMS.auth.login › Filament\Pages › Login POST sMS/logout filament.sMS.auth.logout › Filament\Http › LogoutC… GET|HEAD sMS/orders filament.sMS.pages.orders › App\Filament\Pages\Ord… GET|HEAD sMS/recent-logins filament.sMS.pages.recent-logins › App\Fila… GET|HEAD sanctum/csrf-cookie sanctum.csrf-cookie › Laravel\Sanctum › C… GET|HEAD up ........................................................... Showing [21] routes
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
Replace routes in web.php with what you sent but still getting this issue for some reason [2024-04-14 21:26:28] local.ERROR: Route [login] not defined. {"exception":"[object] (Symfony\Component\Routing\Exception\RouteNotFoundException(code: 0): Route [login] not defined. at /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:477) [stacktrace]
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
Not using sanctum, just what has come by default with FilamentPHP which I believe is auth-guard:web
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
My bad, just applied this to routes/api.php "<?php use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; use App\Http\Controllers\UserOrderController; Route::get('/user', function (Request $request) { return $request->user(); })->middleware('auth:web'); Route::post('/orders/new', [UserOrderController::class, 'store'])->middleware('auth:web');" But now I'm getting this error, I remember now I removed the middlewear to debug the process up untill fetching the user_id, which is now all going correct apart from fetching the user_id "[2024-04-14 20:18:58] local.ERROR: Route [login] not defined. {"exception":"[object] (Symfony\Component\Routing\Exception\RouteNotFoundException(code: 0): Route [login] not defined. at /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:477) [stacktrace]"
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
My web.php is as follows <?php use Illuminate\Support\Facades\Route; Route::get('/', function () { return view('welcome'); }); My api.php is as follows <?php use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; use App\Http\Controllers\UserOrderController; Route::get('/user', function (Request $request) { return $request->user(); })->middleware('auth:web'); Route::post('/orders/new', [UserOrderController::class, 'store']);
42 replies
FFilament
Created by Stitch on 4/14/2024 in #❓┊help
Having issues grabbing user_id using auth-guard:web
The controller is used to store the user order and fetch details from a external API to store to the DB, everything up until that point is fine as evidenced by the logging I've done in laravel.log, except for grabbing the correct user_id that made the order. I'm requesting the controller from my Order.php page in app/Filament/pages/Orders.php
42 replies