Framework: [5.3] How can I change the redirection if I'm not authenticated?

Created on 19 Aug 2016  路  3Comments  路  Source: laravel/framework

So I just set up a L5.3 project and I want my login route to be at "/signin".
My web.php routes file looks like this:

\Route::get('/signin', 'Auth\LoginController@showLoginForm');
\Route::post('/signin', 'Auth\LoginController@login');

When I visit a route with the $this->middleware('auth'); middleware it automatically redirects me to /login - but I want to get redirected to /signin.
I searched through the project but couldn't find the place where this gets set!

Thanks!

Most helpful comment

Actually it was alot easier!
I just had to change the redirect in app/Exceptions/Handler:

protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }

        return redirect()->guest(action('Auth\LoginController@showLoginForm'));
    }

All 3 comments

Actually it was alot easier!
I just had to change the redirect in app/Exceptions/Handler:

protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }

        return redirect()->guest(action('Auth\LoginController@showLoginForm'));
    }

not working

Was this page helpful?
0 / 5 - 0 ratings