jonnybarnes.uk/app/Http/Middleware/MyAuthMiddleware.php
Jonny Barnes 2e79492b01 Protect admin routes with new eloquent sessions
When using Laravel’s own auth middleware an exception would then get
thrown which was being sent to Slack, hmmm.

So I modified the original MyAuthMiddleware to use the Auth facade
instead of a custom session key.

A logout page has also been added.
2019-03-23 09:35:07 +00:00

29 lines
615 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class MyAuthMiddleware
{
/**
* Check the user is logged in.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
if (Auth::check($request->user()) == false) {
//theyre not logged in, so send them to login form
return redirect()->route('login');
}
return $next($request);
}
}