Fix and test Redirection when already authenticated

This commit is contained in:
Bubka 2020-03-05 17:14:57 +01:00
parent 48e3d22446
commit 20970606a3
5 changed files with 31 additions and 1 deletions

View File

@ -18,7 +18,7 @@ class RedirectIfAuthenticated
public function handle($request, Closure $next, $guard = null) public function handle($request, Closure $next, $guard = null)
{ {
if (Auth::guard($guard)->check()) { if (Auth::guard($guard)->check()) {
return redirect('/home'); return response()->json(['message' => __('auth.already_authenticated')], 400);
} }
return $next($request); return $next($request);

View File

@ -6,6 +6,7 @@ export default {
"register": "Register", "register": "Register",
"hello": "Hi {username} !", "hello": "Hi {username} !",
"throttle": "Too many login attempts. Please try again in {seconds} seconds.", "throttle": "Too many login attempts. Please try again in {seconds} seconds.",
"already_authenticated": "Already authenticated",
"confirm": { "confirm": {
"logout": "Are you sure you want to log out?" "logout": "Are you sure you want to log out?"
}, },
@ -267,6 +268,7 @@ export default {
"register": "Créer un compte", "register": "Créer un compte",
"hello": "Hi {username} !", "hello": "Hi {username} !",
"throttle": "Trop de tentatives de connexion. Veuillez réessayer dans {seconds} secondes.", "throttle": "Trop de tentatives de connexion. Veuillez réessayer dans {seconds} secondes.",
"already_authenticated": "Déjà authentifié",
"confirm": { "confirm": {
"logout": "Etes-vous sûrs de vouloir vous déconnecter ?" "logout": "Etes-vous sûrs de vouloir vous déconnecter ?"
}, },

View File

@ -18,6 +18,7 @@ return [
'register' => 'Register', 'register' => 'Register',
'hello' => 'Hi {username} !', 'hello' => 'Hi {username} !',
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
'already_authenticated' => 'Already authenticated',
'confirm' => [ 'confirm' => [
'logout' => 'Are you sure you want to log out?', 'logout' => 'Are you sure you want to log out?',
], ],

View File

@ -18,6 +18,7 @@ return [
'register' => 'Créer un compte', 'register' => 'Créer un compte',
'hello' => 'Hi {username} !', 'hello' => 'Hi {username} !',
'throttle' => 'Trop de tentatives de connexion. Veuillez réessayer dans :seconds secondes.', 'throttle' => 'Trop de tentatives de connexion. Veuillez réessayer dans :seconds secondes.',
'already_authenticated' => 'Déjà authentifié',
'confirm' => [ 'confirm' => [
'logout' => 'Etes-vous sûrs de vouloir vous déconnecter ?', 'logout' => 'Etes-vous sûrs de vouloir vous déconnecter ?',
], ],

View File

@ -46,6 +46,32 @@ class LoginTest extends TestCase
} }
/**
* test User login via API
*
* @test
*/
public function testUserLoginAlreadyAuthenticated()
{
$response = $this->json('POST', '/api/login', [
'email' => $this->user->email,
'password' => 'password'
]);
$response = $this->actingAs($this->user, 'api')
->json('POST', '/api/login', [
'email' => $this->user->email,
'password' => 'password'
]);
$response->assertStatus(400)
->assertJson([
'message' => __('auth.already_authenticated')
]);
}
/** /**
* test User login with missing values via API * test User login with missing values via API
* *