Skip to content

Commit 2c4bcfb

Browse files
committed
Fix register action when logged in
1 parent bec3894 commit 2c4bcfb

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/Controllers/RegisterController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public function registerView()
4545
*/
4646
public function registerAction(): RedirectResponse
4747
{
48+
if (auth()->loggedIn()) {
49+
return redirect()->to(config('Auth')->registerRedirect());
50+
}
51+
4852
// Check if registration is allowed
4953
if (! setting('Auth.allowRegistration')) {
5054
return redirect()->back()->withInput()

tests/Controllers/RegisterTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,23 @@ public function testRegisterRedirectsIfLoggedIn(): void
160160
$result->assertRedirectTo(config('Auth')->registerRedirect());
161161
}
162162

163+
public function testRegisterActionRedirectsIfLoggedIn(): void
164+
{
165+
// log them in
166+
session()->set('user', ['id' => $this->user->id]);
167+
168+
$result = $this->withSession()->post('/register', [
169+
'username' => 'JohnDoe',
170+
'email' => '[email protected]',
171+
'password' => 'secret things might happen here',
172+
'password_confirm' => 'secret things might happen here',
173+
]);
174+
175+
$result->assertStatus(302);
176+
$result->assertRedirect();
177+
$result->assertRedirectTo(config('Auth')->registerRedirect());
178+
}
179+
163180
protected function setupConfig(): void
164181
{
165182
$config = config('Validation');

0 commit comments

Comments
 (0)