diff --git a/src/Concerns/InteractsWithAuthentication.php b/src/Concerns/InteractsWithAuthentication.php index f2736dcbc..85af0a5a1 100644 --- a/src/Concerns/InteractsWithAuthentication.php +++ b/src/Concerns/InteractsWithAuthentication.php @@ -28,7 +28,7 @@ public function loginAs($userId, $guard = null) { $userId = method_exists($userId, 'getKey') ? $userId->getKey() : $userId; - return $this->visit(rtrim(route('dusk.login', ['userId' => $userId, 'guard' => $guard]))); + return $this->visit(rtrim(route('dusk.login', ['userId' => $userId, 'guard' => $guard], $this->shouldUseAbsoluteRouteForAuthentication()))); } /** @@ -39,7 +39,7 @@ public function loginAs($userId, $guard = null) */ public function logout($guard = null) { - return $this->visit(rtrim(route('dusk.logout', ['guard' => $guard]), '/')); + return $this->visit(rtrim(route('dusk.logout', ['guard' => $guard], $this->shouldUseAbsoluteRouteForAuthentication()), '/')); } /** @@ -50,7 +50,7 @@ public function logout($guard = null) */ protected function currentUserInfo($guard = null) { - $response = $this->visit(route('dusk.user', ['guard' => $guard])); + $response = $this->visit(route('dusk.user', ['guard' => $guard], $this->shouldUseAbsoluteRouteForAuthentication())); return json_decode(strip_tags($response->driver->getPageSource()), true); } @@ -104,4 +104,14 @@ public function assertAuthenticatedAs($user, $guard = null) return $this; } + + /** + * Determine if route() should use an absolute path. + * + * @return bool + */ + private function shouldUseAbsoluteRouteForAuthentication() + { + return config('dusk.domain') !== null; + } } diff --git a/src/DuskServiceProvider.php b/src/DuskServiceProvider.php index 329958c82..b814f63a1 100644 --- a/src/DuskServiceProvider.php +++ b/src/DuskServiceProvider.php @@ -15,11 +15,11 @@ class DuskServiceProvider extends ServiceProvider public function boot() { if (! $this->app->environment('production')) { - Route::group([ + Route::group(array_filter([ 'prefix' => config('dusk.path', '_dusk'), 'domain' => config('dusk.domain', null), 'middleware' => 'web', - ], function () { + ]), function () { Route::get('/login/{userId}/{guard?}', [ 'uses' => 'Laravel\Dusk\Http\Controllers\UserController@login', 'as' => 'dusk.login',