Skip to content

Commit

Permalink
fix: redirect after login now works correctly for both wp and wc
Browse files Browse the repository at this point in the history
  • Loading branch information
williarin committed Jul 26, 2023
1 parent d2e6fdb commit 2d5904a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Security/UserAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,35 @@ public function authenticate(Request $request): Passport

public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
{
$redirectPath = $this->getRedirectPath($request);

if ($request->getPathInfo() === '/wp-login.php') {
if ($request->query->has('redirect_to')) {
return new RedirectResponse($request->query->get('redirect_to'));
if ($redirectPath) {
return new RedirectResponse($redirectPath);
}

return new RedirectResponse($this->urlGenerator->generate(Routes::WORDPRESS, [
'path' => ''
]));
}

return $redirectPath
? new RedirectResponse($redirectPath)
: null;
}

private function getRedirectPath(Request $request): ?string
{
$referer = $request->headers->get('referer');

if ($referer && ($queryString = parse_url($referer, PHP_URL_QUERY))) {
parse_str($queryString, $result);

if (!empty($result['redirect_to'])) {
return $result['redirect_to'];
}
}

return null;
}

Expand Down

0 comments on commit 2d5904a

Please sign in to comment.