英文:
"can" middleware doesn't work for multi-domains in laravel
问题
I declared a "Gate" like this:
Gate::define('isAdmin', fn (\App\Models\User $user) => true);
in "AuthServiceProvider" and called that like this:
//dashboard subdomains injection
Route::middleware(['web', 'auth', 'can:isAdmin'])
->domain('dashboard.khassepaz.test')
->group(base_path('routes/dashboard.php'));
//blog subdomains injection
Route::middleware('web')
->domain('blog.khassepaz.test')
->group(base_path('routes/blog.php'));
//normal domains
Route::middleware('web')
->domain('khassepaz.test')
->group(base_path('routes/web.php'));
but when I try to go to "dashboard.khassepaz.test," it redirects to the login page since I have already logged in, I am redirected to the home page that is defined in "RouteServiceProvider" in the "HOME" constant. http://khassepaz.test/
where is my mistake? please help.
NOTE: For information, the user has already registered
UPDATE: public const HOME = '/';
英文:
I declared a "Gate" like this:
Gate::define('isAdmin', fn (\App\Models\User $user) => true);
in "AuthServiceProvider" and called that like this:
//dashboard subdomains injection
Route::middleware(['web', 'auth', 'can:isAdmin']) <----------------
->domain('dashboard.khassepaz.test')
->group(base_path('routes/dashboard.php'));
//blog subdomains injection
Route::middleware('web')
->domain('blog.khassepaz.test')
->group(base_path('routes/blog.php'));
//normal domains
Route::middleware('web')
->domain('khassepaz.test')
->group(base_path('routes/web.php'));
but when I try to go to "dashboard.khassepaz.test", it redirects to the login page since I have already logged in, I am redirected to the home page that is defined in "RouteServiceProvider" in the "HOME" constant. http://khassepaz.test/
where is my mistake? please help.
NOTE: For information, the user has already registered
UPDATE: public const HOME = '/';
答案1
得分: 0
前往 config/session.php 并更改
'domain' => env('SESSION_DOMAIN'),
为
'domain' => env('SESSION_DOMAIN', '.maindomain.com'),
现在认证用户在主域和所有子域上都可以识别。
英文:
Go to config/session.php and change
'domain' => env('SESSION_DOMAIN'),
to
'domain' => env('SESSION_DOMAIN', '.maindomain.com'),
now the authenticated user is identified over the main domain and all over subdomains.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论