Skip to content

Commit

Permalink
Merge pull request #10 from yabhq/auth-custom-guards
Browse files Browse the repository at this point in the history
Auth custom guards
  • Loading branch information
chrisblackwell authored Apr 11, 2019
2 parents 9e211f6 + 216c453 commit fd89f49
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function store(LoginRequest $request)
{
$credentials = $request->only(['email', 'password']);

if (! $token = auth()->attempt($credentials)) {
if (! $token = $this->guard()->attempt($credentials)) {
return response()->json(['error' => 'Unauthorized'], 401);
}

Expand All @@ -33,7 +33,7 @@ public function store(LoginRequest $request)
*/
public function destroy()
{
auth()->logout();
$this->guard()->logout();

return response()->json(['message' => 'Successfully logged out']);
}
Expand All @@ -45,7 +45,7 @@ public function destroy()
*/
public function update()
{
return $this->respondWithToken(auth()->refresh());
return $this->respondWithToken($this->guard()->refresh());
}

/**
Expand All @@ -60,7 +60,17 @@ protected function respondWithToken($token)
return response()->json([
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth()->factory()->getTTL() * 60
'expires_in' => $this->guard()->factory()->getTTL() * 60
]);
}

/**
* Get the guard to be used for login, logout and token refreshes.
*
* @return \Illuminate\Contracts\Auth\StatefulGuard
*/
protected function guard()
{
return auth()->guard();
}
}
4 changes: 4 additions & 0 deletions tests/ForgotPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public function entering_a_valid_email_address_sends_the_forgot_password_email()

$response->assertOk();

$this->assertDatabaseHas('password_resets', [
'email' => $user->email,
]);

Notification::assertSentTo($user, ResetPassword::class);
}
}
Expand Down

0 comments on commit fd89f49

Please sign in to comment.