Skip to content

Commit bec3894

Browse files
committed
Fix register when logged in
1 parent 93f607f commit bec3894

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Controllers/RegisterController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class RegisterController extends BaseController
2727
*/
2828
public function registerView()
2929
{
30+
if (auth()->loggedIn()) {
31+
return redirect()->to(config('Auth')->registerRedirect());
32+
}
33+
3034
// Check if registration is allowed
3135
if (! setting('Auth.allowRegistration')) {
3236
return redirect()->back()->withInput()

tests/Controllers/RegisterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
use CodeIgniter\Test\FeatureTestTrait;
1212
use Config\Services;
1313
use Tests\Support\DatabaseTestCase;
14+
use Tests\Support\FakeUser;
1415

1516
/**
1617
* @internal
1718
*/
1819
final class RegisterTest extends DatabaseTestCase
1920
{
2021
use FeatureTestTrait;
22+
use FakeUser;
2123

2224
protected $namespace;
2325

@@ -146,6 +148,18 @@ public function testRegisterRedirectsToActionIfDefined(): void
146148
]);
147149
}
148150

151+
public function testRegisterRedirectsIfLoggedIn(): void
152+
{
153+
// log them in
154+
session()->set('user', ['id' => $this->user->id]);
155+
156+
$result = $this->withSession()->get('/register');
157+
158+
$result->assertStatus(302);
159+
$result->assertRedirect();
160+
$result->assertRedirectTo(config('Auth')->registerRedirect());
161+
}
162+
149163
protected function setupConfig(): void
150164
{
151165
$config = config('Validation');

0 commit comments

Comments
 (0)