English 中文(简体)
Laravel wrong redirecting to login page after login
原标题:

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.

enter image description here

enter image description here

问题回答

暂无回答




相关问题
Laravel wrong redirecting to login page after login

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 ...

Multitenancy and Partitaioning

HI There, i have to make my application SAAS compliant .For achieving multi tenancy , i was thing of partitioning the data , and each partition will be for a tenant. and this partitioning will be ...

Zend Framework - pass variable to every controller

I m working on multi-tenant application in Zend Framework which gets it s tenantID from the subdomain name (mod_rewrite -> index.php -> matches it against the database). My question is - how do I set ...

Multiple application instances on the same database

I m writing an application that that I m going to provide as a service and also as a standalone application. It s written in Zend Framework and uses MySQL. When providing it as a service I want users ...

Multitenant DB: Why put a TenantID column in every table?

Every tutorial I ve seen about Multitenant database models tells you to put the TenantID in every single table: zoos ------- id zoo_name tenant_id animals ------- id zoo_id animal_name tenant_id ...

热门标签