Skip to content

Commit ca68634

Browse files
committed
Use redirectTo method and change default redirect to the welcome page
1 parent fe793a3 commit ca68634

File tree

7 files changed

+12
-44
lines changed

7 files changed

+12
-44
lines changed

src/Auth/RedirectsUsers.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ trait RedirectsUsers
1010
{
1111
/**
1212
* Get the post register / login redirect path.
13-
*
14-
* @return string
1513
*/
16-
public function redirectPath()
14+
public function redirectPath(): string
1715
{
1816
if (method_exists($this, 'redirectTo')) {
1917
return $this->redirectTo();
2018
}
2119

22-
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
20+
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/';
2321
}
2422
}

stubs/Identities/Auth/ConnectController.stub

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace App\Http\Controllers\Identities\Auth;
44

55
use App\User;
66
use App\Http\Controllers\Controller;
7-
use App\Providers\RouteServiceProvider;
87
use Oneofftech\Identities\Auth\ConnectUserIdentity;
98

109
class ConnectController extends Controller
@@ -25,18 +24,9 @@ class ConnectController extends Controller
2524

2625
/**
2726
* Where to redirect users after connection.
28-
*
29-
* @var string
3027
*/
31-
protected $redirectTo = RouteServiceProvider::HOME;
32-
33-
/**
34-
* Create a new controller instance.
35-
*
36-
* @return void
37-
*/
38-
public function __construct()
28+
protected function redirectTo(): string
3929
{
40-
$this->middleware('auth');
30+
return '/';
4131
}
4232
}

stubs/Identities/Auth/LoginController.stub

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Http\Controllers\Identities\Auth;
44

55
use App\Http\Controllers\Controller;
6-
use App\Providers\RouteServiceProvider;
76
use Oneofftech\Identities\Auth\AuthenticatesUsersWithIdentity;
87

98
class LoginController extends Controller
@@ -24,18 +23,9 @@ class LoginController extends Controller
2423

2524
/**
2625
* Where to redirect users after login.
27-
*
28-
* @var string
2926
*/
30-
protected $redirectTo = RouteServiceProvider::HOME;
31-
32-
/**
33-
* Create a new controller instance.
34-
*
35-
* @return void
36-
*/
37-
public function __construct()
27+
protected function redirectTo(): string
3828
{
39-
$this->middleware('guest');
29+
return '/';
4030
}
4131
}

stubs/Identities/Auth/RegisterController.stub

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use App\User;
66
use Illuminate\Support\Str;
77
use App\Http\Controllers\Controller;
88
use Illuminate\Support\Facades\Hash;
9-
use App\Providers\RouteServiceProvider;
109
use Illuminate\Support\Facades\Validator;
1110
use Oneofftech\Identities\Auth\RegistersUsersWithIdentity;
1211

@@ -27,19 +26,10 @@ class RegisterController extends Controller
2726

2827
/**
2928
* Where to redirect users after registration.
30-
*
31-
* @var string
32-
*/
33-
protected $redirectTo = RouteServiceProvider::HOME;
34-
35-
/**
36-
* Create a new controller instance.
37-
*
38-
* @return void
3929
*/
40-
public function __construct()
30+
protected function redirectTo(): string
4131
{
42-
$this->middleware('guest');
32+
return '/';
4333
}
4434

4535
/**

tests/Unit/ConnectControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function test_connect_creates_identity()
9393
$response = $this->actingAs($user)
9494
->get(route('oneofftech::connect.callback', ['provider' => 'gitlab']));
9595

96-
$response->assertRedirect('http://localhost/home');
96+
$response->assertRedirect('http://localhost');
9797

9898
$updatedIdentity = $user->identities->first();
9999

@@ -144,7 +144,7 @@ public function test_connect_updates_existing_identity()
144144
$response = $this->actingAs($user)
145145
->get(route('oneofftech::connect.callback', ['provider' => 'gitlab']));
146146

147-
$response->assertRedirect('http://localhost/home');
147+
$response->assertRedirect('http://localhost');
148148

149149
$updatedIdentity = $user->identities->first();
150150

tests/Unit/LoginControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function test_user_login()
6767

6868
$response = $this->get(route('oneofftech::login.callback', ['provider' => 'gitlab']));
6969

70-
$response->assertRedirect('http://localhost/home');
70+
$response->assertRedirect('http://localhost');
7171

7272
$this->assertAuthenticatedAs($user);
7373
}

tests/Unit/RegistrationControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function test_user_can_be_registered()
5656

5757
$response = $this->get(route('oneofftech::register.callback', ['provider' => 'gitlab']));
5858

59-
$response->assertRedirect('http://localhost/home');
59+
$response->assertRedirect('http://localhost');
6060

6161
$user = User::first();
6262

0 commit comments

Comments
 (0)