Skip to content

Commit

Permalink
Added JWT middleware and updated services file.
Browse files Browse the repository at this point in the history
  • Loading branch information
izniburak committed Aug 3, 2019
1 parent 1f30467 commit 610690f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ nur - simple framework for PHP
- Routing system and basic Middleware support. ([PHP-Router](https://github.com/izniburak/php-router))
- Symfony Request and Response components. ([Symfony HttpFoundation](https://symfony.com/doc/current/components/http_foundation.html))
- PDOx Query Builder Class. ([PDOx](https://github.com/izniburak/pdox))
- Authentication component.
- Authentication component. (with **JWT** and **Basic Auth**)
- Some **Laravel 5.8** Packages supports.
- Eloquent ORM support. ([Laravel Eloquent ORM](https://laravel.com/docs/eloquent))
- Laravel Query Builder support. ([Laravel Query Builder](https://laravel.com/docs/queries))
Expand Down
29 changes: 29 additions & 0 deletions app/Middlewares/Jwt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Middlewares;

use Nur\Auth\Jwt\JwtException;
use Nur\Middleware\Middleware;

class Jwt extends Middleware
{
/**
* This method will be triggered
* when the middleware is called
*
* @return mixed
*/
public function handle()
{
try {
auth()->jwt()->check();
} catch (JwtException $e) {
return response()->json([
'success' => false,
'error' => $e->getMessage(),
], 401);
}

return true;
}
}
2 changes: 2 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Nur\Providers\Log::class,
Nur\Providers\Hash::class,
Nur\Providers\Validation::class,
// Nur\Providers\Jwt::class,
// Nur\Providers\Pdox::class,
// Nur\Providers\Html::class,
// Nur\Providers\Cache::class,
Expand Down Expand Up @@ -62,6 +63,7 @@
'Crypt' => Nur\Facades\Crypt::class,
'Log' => Nur\Facades\Log::class,
'Validation' => Nur\Facades\Validation::class,
'Jwt' => Nur\Facades\Jwt::class,

],

Expand Down

0 comments on commit 610690f

Please sign in to comment.