@cocreate/users 1.36.8 → 1.36.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.36.9](https://github.com/CoCreate-app/CoCreate-users/compare/v1.36.8...v1.36.9) (2024-04-29)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * check if url is not the same as current prior to applying location.href ([bda51bb](https://github.com/CoCreate-app/CoCreate-users/commit/bda51bb23bc9b3adc19864fcf78c444d1462b781))
7
+
1
8
  ## [1.36.8](https://github.com/CoCreate-app/CoCreate-users/compare/v1.36.7...v1.36.8) (2024-02-18)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/users",
3
- "version": "1.36.8",
3
+ "version": "1.36.9",
4
4
  "description": "A simple users component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "users",
package/src/client.js CHANGED
@@ -186,27 +186,31 @@ const CoCreateUser = {
186
186
  if (data.user_id && data.user_id !== Crud.socket.user_id || data.clientId && data.clientId !== Crud.socket.clientId)
187
187
  return
188
188
 
189
+ let redirectTag
189
190
  if (data.userStatus == 'on' || data.userStatus == 'idle') {
190
- let redirectTag = document.querySelector('[session="true"]');
191
-
192
- if (redirectTag) {
193
- let redirectLink = redirectTag.getAttribute('href');
194
- if (redirectLink) {
195
- document.location.href = redirectLink;
196
- }
197
- }
198
-
191
+ redirectTag = document.querySelector('[session="true"]');
199
192
  } else if (data.userStatus == 'off') {
200
- let redirectTag = document.querySelector('[session="false"]');
193
+ redirectTag = document.querySelector('[session="false"]');
194
+ }
201
195
 
202
- if (redirectTag) {
203
- let redirectLink = redirectTag.getAttribute('href');
204
- if (redirectLink) {
196
+ if (redirectTag) {
197
+ let redirectLink = redirectTag.getAttribute('href');
198
+ if (redirectLink) {
199
+ if (data.userStatus == 'off') {
205
200
  localStorage.removeItem("user_id");
206
201
  localStorage.removeItem("token");
207
- document.location.href = redirectLink;
208
202
  }
203
+
204
+ // Normalize both URLs to compare paths in a uniform way
205
+ const currentPath = new URL(location.href).pathname.replace('/index.html', '/');
206
+ const targetPath = new URL(redirectLink, location.href).pathname.replace('/index.html', '/');
207
+
208
+ if (currentPath !== targetPath) {
209
+ location.href = redirectLink;
210
+ }
211
+
209
212
  }
213
+
210
214
  }
211
215
 
212
216
  if (data.userStatus) {