saasufy-components 3.26.2 → 3.27.0

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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/package.json +1 -1
  3. package/socket.js +11 -2
package/README.md CHANGED
@@ -251,6 +251,7 @@ A Saasufy component which integrates with data from Saasufy is known as a `socke
251
251
  - `auth-token-name`: Allows you to specify a custom key for your token - This will be used as the key in localStorage. You generally do not need to set this attribute. It is intended for situations were an app has multiple `socket-provider` elements connecting different services with different/separate authentication flows.
252
252
  - `disable-tab-sync`: By default, the socket provider synchronizes socket auth state across multiple tabs via localStorage. If this attribute is set, then the socket auth state will not sync automatically and a manual page refresh may be necessary to update to the latest auth state.
253
253
  - `socket-options`: Can be used to set options on the inner `socket`. Must be in the format `option1:type1=value1,option2:type2=value2`; the type of each option can be string, boolean or number. If not specified, the default type is string.
254
+ - `disconnect-on-deauth`: If this attribute is set, the underlying socket will be disconnected if the socket becomes unauthenticated. This means that components will not receive real-time updates until the user's next interaction (which will cause the socket to reconnect). If this attribute is not set, the socket will attempt to reconnect immediately after losing authentication.
254
255
 
255
256
  ### collection-browser
256
257
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "3.26.2",
3
+ "version": "3.27.0",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/socket.js CHANGED
@@ -120,9 +120,18 @@ export class SocketProvider extends HTMLElement {
120
120
  }
121
121
  let disableTabSync = this.hasAttribute('disable-tab-sync');
122
122
  if (!disableTabSync) {
123
- this.storageChangeWatcher = (event) => {
123
+ this.storageChangeWatcher = async (event) => {
124
124
  if (event.storageArea === window.localStorage && event.key === this.saasufySocket.options.authTokenName) {
125
- this.saasufySocket.reconnect();
125
+ if (event.newValue == null) {
126
+ await this.saasufySocket.deauthenticate();
127
+ if (this.hasAttribute('disconnect-on-deauth')) {
128
+ this.saasufySocket.disconnect(1000, 'log-out');
129
+ } else {
130
+ this.saasufySocket.reconnect(1000, 'log-out');
131
+ }
132
+ } else {
133
+ this.saasufySocket.reconnect(1000, 'log-out');
134
+ }
126
135
  }
127
136
  };
128
137
  window.addEventListener('storage', this.storageChangeWatcher);