-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to replace default guest middleware
- Loading branch information
1 parent
04f6211
commit 328e0ee
Showing
3 changed files
with
54 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Grosv\LaravelPasswordlessLogin; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class HandleAuthenticatedUsers | ||
{ | ||
public function handle(Request $request, \Closure $next, ...$guards) | ||
{ | ||
$guards = empty($guards) ? [null] : $guards; | ||
|
||
foreach ($guards as $guard) { | ||
if (Auth::guard($guard)->check()) { | ||
$home = class_exists(\App\Providers\RouteServiceProvider::class) | ||
? \App\Providers\RouteServiceProvider::HOME | ||
: config('laravel-passwordless-login.redirect_on_success', '/'); | ||
|
||
return redirect($request->get('redirect_to', $home)); | ||
} | ||
} | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
<?php | ||
|
||
use Grosv\LaravelPasswordlessLogin\LaravelPasswordlessLoginController; | ||
use Grosv\LaravelPasswordlessLogin\HandleAuthenticatedUsers; | ||
use Illuminate\Support\Facades\Route; | ||
|
||
Route::get( | ||
config('laravel-passwordless-login.login_route').'/{uid}', | ||
[LaravelPasswordlessLoginController::class, 'login'] | ||
)->middleware(['web', 'guest'])->name(config('laravel-passwordless-login.login_route_name')); | ||
)->middleware(['web', HandleAuthenticatedUsers::class])->name(config('laravel-passwordless-login.login_route_name')); | ||
|
||
Route::get('/laravel_passwordless_login_redirect_test_route', [LaravelPasswordlessLoginController::class, 'redirectTestRoute'])->middleware('auth'); | ||
Route::get('/laravel_passwordless_login_redirect_overridden_route', [LaravelPasswordlessLoginController::class, 'redirectTestRoute'])->middleware('auth'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters