Skip to content

Commit

Permalink
Fix redirect unauthenticated function issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tisuchi committed Feb 21, 2018
1 parent 7638fdd commit 9710b01
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ToDos.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ OK == 5. Please remove the mega menu for now at the very top, also the search, l
OK == 8. for the login page. the forgot password function is needed. and the password is needed encrypt in the database.


OK == 9. Redirect to login page if session has expired




Expand Down
20 changes: 20 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Exceptions;

use Exception;
use Illuminate\Auth\AuthenticationException as AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
Expand Down Expand Up @@ -50,4 +51,23 @@ public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}


/**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}

return redirect()->guest('login');
}


}
4 changes: 2 additions & 2 deletions app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class RedirectIfAuthenticated
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
//return redirect('/home');
return redirect('/login');
return redirect('/home');
//return redirect('/login');
}

return $next($request);
Expand Down

0 comments on commit 9710b01

Please sign in to comment.