Skip to content

Commit a7990c3

Browse files
author
Pascal Baljet
committed
Better redirect
1 parent fe51c65 commit a7990c3

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Publish the database migration, config file and email view:
2323
php artisan vendor:publish --provider="ProtoneMedia\LaravelVerifyNewEmail\ServiceProvider"
2424
```
2525

26+
You can set the redirect path in the `verify-new-email.php` config file.
27+
2628
The expire time of the verification URLs can be changed by updating the `auth.verification.expire` setting and defaults to 60 minutes.
2729

2830
## Usage

config/config.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
return [
44
/**
5-
* Here you can specify the name of a custom route to redirect to after verification.
5+
* Here you can specify the name of a custom route to handle the verification.
66
*/
77
'route' => null,
88

9+
/**
10+
* Here you can specify the path to redirect to after verification.
11+
*/
12+
'redirect_to' => '/home',
13+
914
/**
1015
* Wether to login the user after successfully verifying its email.
1116
*/

src/Http/VerifiesPendingEmails.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
namespace ProtoneMedia\LaravelVerifyNewEmail\Http;
44

5-
use Illuminate\Foundation\Auth\RedirectsUsers;
65
use Illuminate\Support\Facades\Auth;
76
use ProtoneMedia\LaravelVerifyNewEmail\PendingUserEmail;
87

98
trait VerifiesPendingEmails
109
{
11-
use RedirectsUsers;
12-
1310
/**
1411
* Mark the user's new email address as verified.
1512
*
@@ -29,6 +26,6 @@ public function verify(string $token)
2926
Auth::guard()->login($user);
3027
}
3128

32-
return redirect($this->redirectPath())->with('verified', true);
29+
return redirect(config('verify-new-email.redirect_to'))->with('verified', true);
3330
}
3431
}

src/Http/VerifyNewEmailController.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ class VerifyNewEmailController extends Controller
1818

1919
use VerifiesPendingEmails;
2020

21-
/**
22-
* Where to redirect users after verification.
23-
*
24-
* @var string
25-
*/
26-
protected $redirectTo = '/home';
27-
2821
/**
2922
* Create a new controller instance.
3023
*

tests/VerifyNewEmailControllerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace ProtoneMedia\LaravelVerifyNewEmail\Tests;
44

55
use Illuminate\Auth\Events\Verified;
6+
use Illuminate\Http\RedirectResponse;
67
use Illuminate\Support\Facades\Event;
78
use Illuminate\Support\Facades\Mail;
89
use ProtoneMedia\LaravelVerifyNewEmail\Http\InvalidVerificationLinkException;
@@ -28,7 +29,10 @@ public function it_updates_the_user_email_and_deletes_the_pending_email()
2829

2930
$pendingUserEmail = $user->newEmail('new@example.com');
3031

31-
app(VerifyNewEmailController::class)->verify($pendingUserEmail->token);
32+
$redirect = app(VerifyNewEmailController::class)->verify($pendingUserEmail->token);
33+
34+
$this->assertInstanceOf(RedirectResponse::class, $redirect);
35+
$this->assertEquals('http://localhost/home', $redirect->getTargetUrl());
3236

3337
$user = $user->fresh();
3438

0 commit comments

Comments
 (0)