Skip to content

Commit

Permalink
fix: check if url is not the same as current prior to applying locati…
Browse files Browse the repository at this point in the history
…on.href
  • Loading branch information
frankpagan committed Apr 29, 2024
1 parent 36cbd8f commit bda51bb
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,31 @@ const CoCreateUser = {
if (data.user_id && data.user_id !== Crud.socket.user_id || data.clientId && data.clientId !== Crud.socket.clientId)
return

let redirectTag
if (data.userStatus == 'on' || data.userStatus == 'idle') {
let redirectTag = document.querySelector('[session="true"]');

if (redirectTag) {
let redirectLink = redirectTag.getAttribute('href');
if (redirectLink) {
document.location.href = redirectLink;
}
}

redirectTag = document.querySelector('[session="true"]');
} else if (data.userStatus == 'off') {
let redirectTag = document.querySelector('[session="false"]');
redirectTag = document.querySelector('[session="false"]');
}

if (redirectTag) {
let redirectLink = redirectTag.getAttribute('href');
if (redirectLink) {
if (redirectTag) {
let redirectLink = redirectTag.getAttribute('href');
if (redirectLink) {
if (data.userStatus == 'off') {
localStorage.removeItem("user_id");
localStorage.removeItem("token");
document.location.href = redirectLink;
}

// Normalize both URLs to compare paths in a uniform way
const currentPath = new URL(location.href).pathname.replace('/index.html', '/');
const targetPath = new URL(redirectLink, location.href).pathname.replace('/index.html', '/');

if (currentPath !== targetPath) {
location.href = redirectLink;
}

}

}

if (data.userStatus) {
Expand Down

0 comments on commit bda51bb

Please sign in to comment.