Skip to content

Commit

Permalink
Fix middleware problem
Browse files Browse the repository at this point in the history
  • Loading branch information
francescomalatesta committed Apr 16, 2018
1 parent 0ce6bd1 commit 67170d8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/Api/V1/Controllers/LogoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LogoutController extends Controller
*/
public function __construct()
{
$this->middleware('auth:api', []);
$this->middleware('jwt.auth', []);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Api/V1/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UserController extends Controller
*/
public function __construct()
{
$this->middleware('auth:api', []);
$this->middleware('jwt.auth', []);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace App\Http;

use Tymon\JWTAuth\Middleware\RefreshToken;
use Tymon\JWTAuth\Middleware\GetUserFromToken;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Tymon\JWTAuth\Http\Middleware\RefreshToken;

class Kernel extends HttpKernel
{
Expand Down Expand Up @@ -55,7 +54,7 @@ class Kernel extends HttpKernel
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,

'jwt.auth' => GetUserFromToken::class,
'jwt.refresh' => RefreshToken::class,
'jwt.auth' => \Tymon\JWTAuth\Http\Middleware\Authenticate::class,
'jwt.refresh' => RefreshToken::class
];
}
9 changes: 2 additions & 7 deletions tests/Functional/Api/V1/Controllers/LogoutControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ public function testLogout()
$responseJSON = json_decode($response->getContent(), true);
$token = $responseJSON['token'];

$this->post('api/auth/logout', [], [
'Authorization' => 'Bearer ' . $token
])->assertStatus(200);

$this->post('api/auth/logout', [], [
'Authorization' => 'Bearer ' . $token
])->assertStatus(500);
$this->post('api/auth/logout?token=' . $token, [], [])->assertStatus(200);
$this->post('api/auth/logout?token=' . $token, [], [])->assertStatus(401);
}
}
4 changes: 1 addition & 3 deletions tests/Functional/Api/V1/Controllers/UserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public function testMe()
$responseJSON = json_decode($response->getContent(), true);
$token = $responseJSON['token'];

$this->get('api/auth/me', [], [
'Authorization' => 'Bearer ' . $token
])->assertJson([
$this->get('api/auth/me?token=' . $token, [], [])->assertJson([
'name' => 'Test',
'email' => 'test@email.com'
])->isOk();
Expand Down

0 comments on commit 67170d8

Please sign in to comment.