diff --git a/src/Facades/RouteHelpers.php b/src/Facades/RouteHelpers.php new file mode 100644 index 000000000..3f1e6edf4 --- /dev/null +++ b/src/Facades/RouteHelpers.php @@ -0,0 +1,16 @@ +config = $config; $this->middleware('twill_guest', ['except' => 'logout']); - $this->redirectTo = $config->get('twill.auth_login_redirect_path', '/'); + $this->redirectTo = RouteHelpers::getAuthRedirectPath(); } /** diff --git a/src/Http/Controllers/Admin/ResetPasswordController.php b/src/Http/Controllers/Admin/ResetPasswordController.php index b589dde0c..582b1d364 100644 --- a/src/Http/Controllers/Admin/ResetPasswordController.php +++ b/src/Http/Controllers/Admin/ResetPasswordController.php @@ -2,6 +2,7 @@ namespace A17\Twill\Http\Controllers\Admin; +use A17\Twill\Facades\RouteHelpers; use Illuminate\Config\Repository as Config; use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Http\Request; @@ -59,7 +60,7 @@ public function __construct(Config $config, Redirector $redirector, ViewFactory $this->viewFactory = $viewFactory; $this->config = $config; - $this->redirectTo = $this->config->get('twill.auth_login_redirect_path', '/'); + $this->redirectTo = RouteHelpers::getAuthRedirectPath(); $this->middleware('twill_guest'); } diff --git a/src/Http/Middleware/RedirectIfAuthenticated.php b/src/Http/Middleware/RedirectIfAuthenticated.php index 4091fb13f..21e51e8af 100644 --- a/src/Http/Middleware/RedirectIfAuthenticated.php +++ b/src/Http/Middleware/RedirectIfAuthenticated.php @@ -2,6 +2,7 @@ namespace A17\Twill\Http\Middleware; +use A17\Twill\Facades\RouteHelpers; use Closure; use Illuminate\Config\Repository as Config; use Illuminate\Contracts\Auth\Factory as AuthFactory; @@ -40,7 +41,7 @@ public function __construct(AuthFactory $authFactory, Redirector $redirector, Co public function handle($request, Closure $next, $guard = 'twill_users') { if ($this->authFactory->guard($guard)->check()) { - return $this->redirector->to($this->config->get('twill.auth_login_redirect_path', '/')); + return $this->redirector->to(RouteHelpers::getAuthRedirectPath()); } return $next($request); diff --git a/tests/unit/Helpers/RouteHelpersTest.php b/tests/unit/Helpers/RouteHelpersTest.php new file mode 100644 index 000000000..a386f77fd --- /dev/null +++ b/tests/unit/Helpers/RouteHelpersTest.php @@ -0,0 +1,28 @@ + null, 'twill.admin_app_url' => null, 'twill.admin_app_path' => null]); + + $this->assertEquals('/admin', RouteHelpers::getAuthRedirectPath()); + + config(['twill.admin_app_path' => 'twill']); + + $this->assertEquals('/twill', RouteHelpers::getAuthRedirectPath()); + + config(['twill.admin_app_url' => 'https://admin.example.com/']); + + $this->assertEquals('https://admin.example.com/twill', RouteHelpers::getAuthRedirectPath()); + + config(['twill.auth_login_redirect_path' => '/redirect']); + + $this->assertEquals('/redirect', RouteHelpers::getAuthRedirectPath()); + } +}