Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module Route with middleware auth not works #36

Closed
ghost opened this issue Jul 28, 2017 · 6 comments
Closed

Module Route with middleware auth not works #36

ghost opened this issue Jul 28, 2017 · 6 comments

Comments

@ghost
Copy link

ghost commented Jul 28, 2017

Hello, first of all thank you for your works!

I'm using your module, but i think to have find a problem. Default routes of module (web.php) is:

Route::group(array('module' => 'Test', 'middleware' => ['web'], 'namespace' => 'App\Modules\Test\Controllers'), function() {
 //list of my routes, for example 
 Route::get('/test', 'TestController@testIndex');
});

If i would like to protect my routes by middleware, i should change Route::group like that:

Route::group(array('module' => 'Test', 'middleware' => ['**auth**'], 'namespace' => 'App\Modules\Test\Controllers'), function() {
 //list of my routes, for example
 Route::get('/test', 'TestController@testIndex');
});

If i change Route::group like example above when i try to go to "/test", i will be redirect to "/". My suspicion is that auth middleware are not loaded in right way inside module, maybe for different namespace?

The only way i finded to workaround, is to edit routes.php of project (not of module!) adding inside Route::group(['middleware' => ['auth']], function() {
[...]
Route::get('/test', '\App\Modules\Test\Controllers\TestController@testIndex'); [...]

This is no a really useful way to solve the problem. What i can do to solve that problem in web.php of module, istead of edit main Route file?

Best Regards,
Simone

@Artem-Schander
Copy link
Collaborator

Artem-Schander commented Jul 31, 2017

I have no idea if the **auth** is what you really typed into your code. If so, this could be the problem.
I'll check this issue with the following code in a few hours.

Route::group(array('module' => 'Test', 'middleware' => ['web', 'auth'], 'namespace' => 'App\Modules\Test\Controllers'), function() {
 //list of my routes, for example
 Route::get('/test', 'TestController@testIndex');
});

@vireshtripathi
Copy link

vireshtripathi commented Aug 9, 2018

I am also not able to get value from Auth::user() in modules controller. can you please help me out.

Route::group(['module' => 'ScreenColors', 'middleware' => ['web', 'auth'], 'namespace' => 'App\Modules\ScreenColors\Controllers'], function() {
Route::get('/screen_colors', 'ScreenColorsController@index');
});

when i try to get Auth::user() it give me blank.

@Artem-Schander
Copy link
Collaborator

please make sure, you have not defined this route somewhere else without the middleware.
F.A. the route Route::resource('screen_colors', 'ScreenColorsController');

I think i should remove the resourceful api route from the generator.

@vireshtripathi
Copy link

I have not define route any where, my route in module/screencolors/route/web.php

Route::resource('screen_colors', 'ScreenColorsController');

@Artem-Schander
Copy link
Collaborator

could you post the api route of your screen_colors module?

@Artem-Schander
Copy link
Collaborator

closing due to inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants