Skip to content

Commit

Permalink
feat: Created AdminAuthenticate middleware & register in Kernel
Browse files Browse the repository at this point in the history
* If the user is not authenticated then redirects back to the admin login form. So we created  `AdminAuthenticate` middleware which helps to protect our dashboard

* We register this Middleware class `AdminAuthenticate` in Kernel with the short name `auth.admin` so we can consume this one easily on our routes.
  • Loading branch information
ahmadhuss committed May 10, 2021
1 parent 2059362 commit 6995e72
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Kernel extends HttpKernel
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.admin' => \App\Http\Middleware\AdminAuthenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
Expand Down
21 changes: 21 additions & 0 deletions app/Http/Middleware/AdminAuthenticate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;

class AdminAuthenticate extends Middleware
{
/**
* Get the path the admin should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('admin.login');
}
}
}

0 comments on commit 6995e72

Please sign in to comment.