Support the ongoing development of Laravel.io →
Authentication Architecture
Last updated 4 months ago.
0

Try changing

Route::any('/user/login', array('as' => 'login', 'uses' => '[email protected]'));    

to

Route::get('user/login', '[email protected]');
Route::post('user/login', '[email protected]');
Last updated 4 months ago.
0

Hey kreitje,

Even by changing it to:

Route::get('/user/login', array('as' => 'getlogin', 'uses' => '[email protected]'));
Route::post('/user/login', array('as' => 'postlogin', 'uses' => '[email protected]'));

it doesnt work. I still get a redirect loop.

Last updated 4 months ago.
0

Well, what your filter do is:

  • If it's ajax, block.
  • If it isn't redirect to login.

However, when you redirect, the second request is executed in a new instance of the framework, so the filter get re-executed. (you get where there is a loop in your logic?)

What you want to do is probably just block ajax request, but allow normal request to execute normaly. Your filter must be something like:

if (Auth::guest())
{
    if (Request::ajax())
    {
        return Response::make('Unauthorized', 401);
    }
}

Does it solve your problem?

Last updated 4 months ago.
0

Hey Atrakeur,

Why would there be a second re-execution if I set the redirect to a route that is ignored by the filter "assignment" ('except getLogin'):

$this->beforeFilter('auth', array('except' => array('getLogin', 'postLogin')));

Another thing I managed to find but seems quite illogical is that when I remove the filtering from my UserController it tells me that method [index] isn't found. I thought you didn't need to include the VERB (like get, post, delete, put, ...) in your controller routing.

Example: [email protected]index instead of [email protected]getIndex.

As it does seem to show me the dashboard afterwards when using the second example.

Last updated 4 months ago.
0

goowikns said:

Hey Atrakeur,

Why would there be a second re-execution if I set the redirect to a route that is ignored by the filter "assignment" ('except getLogin'):

So this isn't the problem. Maybe you can post a little more code to us so we can help better?

goowikns said:

Another thing I managed to find but seems quite illogical is that when I remove the filtering from my UserController it tells me that method [index] isn't found. I thought you didn't need to include the VERB (like get, post, delete, put, ...) in your controller routing.

Example: [email protected]index instead of [email protected]getIndex.

Well, you don't have to include the verb, But you have to set it to the exact name of the method. So if your method is getIndex, just write getIndex and not just index.

Where are you calling your $this->beforeFilter? What is $this in this context?

If you code is public, please post the github link so we can look at it?

Last updated 4 months ago.
0

Not sure what happened, works now, but it was partially due to the fact my routes weren't correctly written. I'm definetly going to start from scratch as I messed up so many things and generated way to many files at once without actually paying attention.

Last updated 4 months ago.
0

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

goowikns goowikns Joined 18 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.