How to authenticate multiple user groups in Laravel 5?

Asked

Viewed 1,133 times

2

I am trying to create an environment in Laravel 5 where there is the customer access area (Front of the Store) and the administration area of pages, products, etc. (CMS), but the problem is that I am not able to find a way to divide the sessions, for example: when I authenticate an account as an administrator through the CMS login area, that same session is valid for the entire site, and therefore the administrator can access the urls that only authenticated users could, such as the User Panel, for example, and vice versa.

// CMS ADMINISTAÇÃO
Route::group(array('prefix' => '/admin', 'middleware' => ['auth', 'roles'], 'roles' => 'administrator'), function()
{   
    // INDEX
    Route::any('/', array('as' => 'admin', 'uses' => 'Admin\AdminController@Index'));
});

// PAINEL DO USUÁRIO
Route::group(array('middleware' => ['auth', 'roles'], 'roles' => 'client', 'prefix' => '/panel',), function(){
    Route::get('/', array('as' => 'panel', 'uses' => 'PanelController@Index'));
});

For this I implement this role system, which through the Routes identifies if the user has enough permission to access that area, the problem is that after logging in the session would work anywhere, and even if I use itif some filter would still not be allowed I have an administrator account logged in to CMS and another user account logged in to the normal site, unless I split the application into 2, which I would not like to do.

In short, what I want is for both sessions to exist at the same time, without one being able to access what is restricted to another.

How can I fix this?

  • http://answall.com/questions/170252/likeposso-differentiater-authenticat%C3%A7%C3%B5es-no-Laravel-example-administrator-e-usu%C3%A1ri[I think this would solve your problem ][1]

1 answer

1

One solution I see for this situation would be to create an authentication middleware for users, and another for administrators.

  • Hello, Leandro! Welcome to Sopt. I recommend making a tour through the site to know the best ways to answer. So, you could better detail your idea to help the colleague?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.