Unauthenticated exception thrown instead of a login page

The path is set to '/' in the AppPanelProvider config. There is one panel. If I visit the base url of my app, e.g. http://labman (it is hosted on my local dev box, but I can provide a link to a staging site) while I am logged in, everything works as expected, i.e the dashboard is displayed. If I visit the login route, e.g. http://labman/login everything works as expected - I can log in, and I am redirected to the dashboard. However, if I visit the base domain while not logged in, I get an "Unauthenticated" error instead of the login page, which is what I expect. Flare link: https://flareapp.io/share/17WJD3DP
Flare
Unauthenticated. - The error occurred at http://labman/
Solution:
I don't know if this is very elegant, but it is how I resolved my issue: ``` <?php ...
Jump to solution
1 Reply
Solution
WiseWill
WiseWill11mo ago
I don't know if this is very elegant, but it is how I resolved my issue:
<?php

namespace App\Http\Middleware;

use Filament\Http\Middleware\Authenticate as Middleware;

class Authenticate extends Middleware
{
/**
* Handle an unauthenticated user.
*
* @param \Illuminate\Http\Request $request
* @param array $guards
* @return void
*
* @throws \Illuminate\Auth\AuthenticationException
*/
protected function unauthenticated($request, array $guards)
{
if ($request->expectsJson()) {
// Don't offer API requests a login page.
exit(response()->json(['message' => 'Unauthenticated.'], 401));
}

$url = $this->redirectTo($request);
exit("<script>window.location.href = '{$url}';</script>");
}
}
<?php

namespace App\Http\Middleware;

use Filament\Http\Middleware\Authenticate as Middleware;

class Authenticate extends Middleware
{
/**
* Handle an unauthenticated user.
*
* @param \Illuminate\Http\Request $request
* @param array $guards
* @return void
*
* @throws \Illuminate\Auth\AuthenticationException
*/
protected function unauthenticated($request, array $guards)
{
if ($request->expectsJson()) {
// Don't offer API requests a login page.
exit(response()->json(['message' => 'Unauthenticated.'], 401));
}

$url = $this->redirectTo($request);
exit("<script>window.location.href = '{$url}';</script>");
}
}
and
<?php

namespace App\Providers\Filament;

use App\Http\Middleware\Authenticate;
// other classes

class AppPanelProvider extends PanelProvider
{ // normal stuff }
<?php

namespace App\Providers\Filament;

use App\Http\Middleware\Authenticate;
// other classes

class AppPanelProvider extends PanelProvider
{ // normal stuff }
Want results from more Discord servers?
Add your server