-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: Create & Register custom middleware for JWT token
- Loading branch information
Ph.Hitachi
authored and
Ph.Hitachi
committed
Aug 13, 2023
1 parent
2b3202f
commit 64b8019
Showing
2 changed files
with
45 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware\JWT; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Tymon\JWTAuth\Facades\JWTAuth; | ||
use Tymon\JWTAuth\Http\Middleware\BaseMiddleware; | ||
|
||
class AuthenticateMiddleware extends BaseMiddleware | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next | ||
*/ | ||
public function handle(Request $request, Closure $next): Response | ||
{ | ||
$this->authenticate($request); | ||
|
||
return $next($request); | ||
} | ||
|
||
public function authenticate($request) | ||
{ | ||
try { | ||
$this->auth->parseToken()->authenticate(); | ||
} catch (Throwable $e) { | ||
throw $e; | ||
} | ||
} | ||
} |