Skip to content

Commit

Permalink
fix infinite redirect loop
Browse files Browse the repository at this point in the history
  • Loading branch information
isanchez-userfront committed Sep 20, 2024
1 parent 3e1d2d2 commit e040057
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 0 additions & 4 deletions js/userfront.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,5 @@ jQuery(document).ready(function ($) {
$("#userfront-error").css("text-align", "center");
$("#userfront-error").css("max-width", "24rem");
$("#userfront-error").text("Account does not exist.");
if (typeof Userfront !== "undefined" && Userfront.user.email) {
Userfront.logout({ redirect: false });
location.reload();
}
}
});
19 changes: 14 additions & 5 deletions userfront.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ function init()
);
$isLogoutAction = isset($_GET["action"]) && $_GET["action"] == "logout";

$isCreateAccountEnabled = get_option(
'userfront-account-creation',
true
);

if ($isPantheon && $isPostLoginRoute) {
echo '<script type="text/javascript">
function updateCookies() {
Expand Down Expand Up @@ -341,10 +346,6 @@ function updateCookies() {
wp_set_current_user($user->ID);
wp_set_auth_cookie($user->ID, true);
} else {
$isCreateAccountEnabled = get_option(
'userfront-account-creation',
true
);
if ($isCreateAccountEnabled) {
// Insert a new WordPress user
$wpUserId = wp_insert_user(
Expand All @@ -367,12 +368,20 @@ function updateCookies() {
wp_set_current_user($wpUserId);
wp_set_auth_cookie($wpUserId, true);
} else {
delete_cookie($userfrontAccessCookie);
delete_cookie($userfrontIdCookie);
delete_cookie($userfrontRefreshCookie);

delete_cookie($accessCookie, false);
delete_cookie($idCookie, false);
delete_cookie($refreshCookie, false);

redirect("/login?error=no-wordpress-user");
}
}
}

if ($isLoginRoute && !$isPantheon) {
if ($isLoginRoute && !$isPantheon && $isCreateAccountEnabled) {
if (isset($_GET["redirect_to"])) {
redirect($_GET["redirect_to"]);
} else {
Expand Down

0 comments on commit e040057

Please sign in to comment.