In a multi tenancy with subdomain enviroment (http://zapburger.dex.local) when user fills login form with valid data and make login, laravel redirect to dashboard route (as expected) and then redirect back to login page (unexpected).
How can i makes laravel stop redirecting back to login page after login?
The project uses laravel/ui
for authentication scaffold.
Bellow are my configurations:
.env
SESSION_DRIVER=file
SESSION_LIFETIME=120
SESSION_DOMAIN=.dex.local
RouteServiceProvider
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* This is used by Laravel authentication to redirect users after login.
*
* @var string
*/
public const HOME = /dashboard ;
//(... other default methods)
}
DashboardController
class DashboardController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware( auth );
}
//(other methods)
}
web.php
<?php
use IlluminateSupportFacadesRoute;
use AppHttpControllersDashboardController;
use IlluminateSupportFacadesAuth;
Route::get( /dashboard ,[DashboardController::class, dashboard ])->name( dashboard.index );
Auth::routes();
LoginController
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware( guest )->except( logout );
}
/**
* The user has been authenticated.
*
* @param IlluminateHttpRequest $request
* @param mixed $user
* @return mixed
*/
protected function authenticated(Request $request, $user)
{
return redirect()->route( dashboard.index );
}
}
** Http/Kernel.php**
<?php
namespace AppHttp;
use IlluminateFoundationHttpKernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application s global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
// AppHttpMiddlewareTrustHosts::class,
AppHttpMiddlewareTrustProxies::class,
FruitcakeCorsHandleCors::class,
AppHttpMiddlewarePreventRequestsDuringMaintenance::class,
IlluminateFoundationHttpMiddlewareValidatePostSize::class,
AppHttpMiddlewareTrimStrings::class,
IlluminateFoundationHttpMiddlewareConvertEmptyStringsToNull::class,
];
/**
* The application s route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
web => [
AppHttpMiddlewareEncryptCookies::class,
IlluminateCookieMiddlewareAddQueuedCookiesToResponse::class,
IlluminateSessionMiddlewareStartSession::class,
// IlluminateSessionMiddlewareAuthenticateSession::class,
IlluminateViewMiddlewareShareErrorsFromSession::class,
AppHttpMiddlewareVerifyCsrfToken::class,
IlluminateRoutingMiddlewareSubstituteBindings::class,
],
api => [
throttle:api ,
IlluminateRoutingMiddlewareSubstituteBindings::class,
],
];
/**
* The application s route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
auth => AppHttpMiddlewareAuthenticate::class,
auth.basic => IlluminateAuthMiddlewareAuthenticateWithBasicAuth::class,
cache.headers => IlluminateHttpMiddlewareSetCacheHeaders::class,
can => IlluminateAuthMiddlewareAuthorize::class,
guest => AppHttpMiddlewareRedirectIfAuthenticated::class,
password.confirm => IlluminateAuthMiddlewareRequirePassword::class,
signed => IlluminateRoutingMiddlewareValidateSignature::class,
throttle => IlluminateRoutingMiddlewareThrottleRequests::class,
verified => IlluminateAuthMiddlewareEnsureEmailIsVerified::class,
];
}
After inspect Google chrome cookie console i can see laravel_session is changing.