matiasarea
matiasarea
FFilament
Created by matiasarea on 8/15/2023 in #❓┊help
Error redirecting a custom page
I understand. Thank you very much for your time and your answers. One last question, is it possible to add a custom page to non-logged in users?
19 replies
FFilament
Created by matiasarea on 8/15/2023 in #❓┊help
Error redirecting a custom page
Based on what you say, I'm thinking that when I have the middleware Authenticate from filament, the custom page rejects the access because it doesn't have a valid session yet. The LoginSuccess event would have been a good alternative, because it executes that validation after an OK event occurred.
19 replies
FFilament
Created by matiasarea on 8/15/2023 in #❓┊help
Error redirecting a custom page
and use in web.php
Route::get('/', function () {
return redirect('admin/login');
})->middleware([
'single.session',
'password.changeAfterDays',
'password.changeFirstLogin',
]);
Route::get('/', function () {
return redirect('admin/login');
})->middleware([
'single.session',
'password.changeAfterDays',
'password.changeFirstLogin',
]);
19 replies
FFilament
Created by matiasarea on 8/15/2023 in #❓┊help
Error redirecting a custom page
Yes, of course. In the filament.php file inside the config, I declare the following:
'middleware' => [
'auth' => [Authenticate::class],
'base' => [
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DispatchServingFilamentEvent::class,
MirrorConfigToSubpackages::class,
CheckSingleSession::class,
ChangePasswordAfterDays::class,
ChangePasswordFirstLogin::class,
],
],
'middleware' => [
'auth' => [Authenticate::class],
'base' => [
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DispatchServingFilamentEvent::class,
MirrorConfigToSubpackages::class,
CheckSingleSession::class,
ChangePasswordAfterDays::class,
ChangePasswordFirstLogin::class,
],
],
and in Kernel.php:
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\CheckSingleSession::class,
\App\Http\Middleware\ChangePasswordAfterDays::class,
\App\Http\Middleware\ChangePasswordFirstLogin::class,
],

'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:1000,1',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\CheckSingleSession::class,
\App\Http\Middleware\ChangePasswordAfterDays::class,
\App\Http\Middleware\ChangePasswordFirstLogin::class,
],

'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:1000,1',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
19 replies
FFilament
Created by matiasarea on 8/15/2023 in #❓┊help
Error redirecting a custom page
middleware does the following:
public function handle(Request $request, Closure $next)
{
if (Auth::check()) {
$user = Auth::User();
$lastPasswords = PasswordHistory::where('user_id', $user->id)->orderBy('created_at', 'desc')->first();
if ($lastPasswords->created_at->diffInDays(now()) > env('PASSWORD_LIFETIME')) {
// Get previous session
$previous_session = SessionModel::where(
'user_id',
$user->id
)->first();
//

// Delete previous session
Session::getHandler()->destroy($previous_session->id);
//

// Redirect to password change page
// return redirect()->route('password.request');

return redirect(RestartPassword::getUrl());
//
}
}
return $next($request);
}
public function handle(Request $request, Closure $next)
{
if (Auth::check()) {
$user = Auth::User();
$lastPasswords = PasswordHistory::where('user_id', $user->id)->orderBy('created_at', 'desc')->first();
if ($lastPasswords->created_at->diffInDays(now()) > env('PASSWORD_LIFETIME')) {
// Get previous session
$previous_session = SessionModel::where(
'user_id',
$user->id
)->first();
//

// Delete previous session
Session::getHandler()->destroy($previous_session->id);
//

// Redirect to password change page
// return redirect()->route('password.request');

return redirect(RestartPassword::getUrl());
//
}
}
return $next($request);
}
19 replies
FFilament
Created by matiasarea on 8/15/2023 in #❓┊help
Error redirecting a custom page
I understand that the problem in the question is that I am doing the redirect inside a middleware. The case is the following, I have to check if the user has to change the password. So we have a middleware that checks it after the login of the Filament-Brezzy, but I understand that it should not be a middleware but it should be a function that runs after validating the user, but filament brezzy returns:
return app(LoginResponse::class);
return app(LoginResponse::class);
And I'm not being able to change to a return redirect(MyCustumPage::getUrl())
19 replies
FFilament
Created by matiasarea on 8/15/2023 in #❓┊help
Error redirecting a custom page
Hello Patrick, thank you very much for your reply. I have tried it too and I get the same url but the redirect is not done, I get only HTTPS 302 and the content is not shown and it redirects me to the login.
19 replies