Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Unnamed Auth routes returns an error when inside a route group #577

Merged
merged 21 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/Config/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,31 @@ public function registerRedirect(): string
return $this->getUrl($url);
}

/**
* Accepts a string which can be an absolute URL or
* a named route or just a URI path.
* @param string $url
sammyskills marked this conversation as resolved.
Show resolved Hide resolved
* @return string
*/
protected function getUrl(string $url): string
sammyskills marked this conversation as resolved.
Show resolved Hide resolved
{
return strpos($url, 'http') === 0
? $url
: rtrim(site_url($url), '/ ');
// To accommodate all url patterns
$final_url = '';

switch (true) {
case strpos($url, 'http') === 0: // URL begins with 'http'. E.g. http://example.com
sammyskills marked this conversation as resolved.
Show resolved Hide resolved
$final_url = $url;
break;

case route_to($url) !== false: // URL is a named-route
$final_url = url_to($url);
sammyskills marked this conversation as resolved.
Show resolved Hide resolved
break;

default: // URL is a route (URI path)
$final_url = rtrim(site_url($url), '/ ');
break;
}

return $final_url;
}
}
9 changes: 6 additions & 3 deletions src/Config/AuthRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AuthRoutes extends BaseConfig
'get',
'register',
'RegisterController::registerView',
'register', // Route name
],
[
'post',
Expand All @@ -26,6 +27,7 @@ class AuthRoutes extends BaseConfig
'get',
'login',
'LoginController::loginView',
'login', // Route name
],
[
'post',
Expand Down Expand Up @@ -57,26 +59,27 @@ class AuthRoutes extends BaseConfig
'get',
'logout',
'LoginController::logoutAction',
'logout', // Route name
],
],
'auth-actions' => [
[
'get',
'auth/a/show',
'ActionController::show',
'auth-action-show',
'auth-action-show', // Route name
],
[
'post',
'auth/a/handle',
'ActionController::handle',
'auth-action-handle',
'auth-action-handle', // Route name
],
[
'post',
'auth/a/verify',
'ActionController::verify',
'auth-action-verify',
'auth-action-verify', // Route name
],
],
];
Expand Down