saasufy-components 3.20.0 → 3.21.1
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/README.md +25 -4
- package/package.json +1 -1
- package/socket.js +15 -0
package/README.md
CHANGED
|
@@ -166,7 +166,27 @@ Note that the `app-router` can contain any number of pages/routes so the `slot="
|
|
|
166
166
|
</app-router>
|
|
167
167
|
```
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
This example shows how to redirect based on the user's authentication status:
|
|
170
|
+
|
|
171
|
+
```html
|
|
172
|
+
<app-router default-page="/home">
|
|
173
|
+
<template slot="page" route-path="/log-in" auth-redirect="/home" hard-redirect>
|
|
174
|
+
<log-in-form
|
|
175
|
+
hostname="sas.saasufy.com"
|
|
176
|
+
port="443"
|
|
177
|
+
network-symbol="sas"
|
|
178
|
+
chain-module-name="sas_chain"
|
|
179
|
+
secure="true"
|
|
180
|
+
></log-in-form>
|
|
181
|
+
</template>
|
|
182
|
+
<template slot="page" route-path="/home" no-auth-redirect="/log-in">
|
|
183
|
+
<div>This is the home page</div>
|
|
184
|
+
</template>
|
|
185
|
+
<div slot="viewport"></div>
|
|
186
|
+
</app-router>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Note that the app router path is based on `location.hash` so the path section in your browser's address bar needs to start with the `#` character.
|
|
170
190
|
So for example, if your `index.html` file is served up from the URL `http://mywebsite.com`, then, to activate the `/products` route as in the example above, you would need to type the URL `http://mywebsite.com#/products`.
|
|
171
191
|
|
|
172
192
|
**Attributes of app-router**
|
|
@@ -180,9 +200,9 @@ So for example, if your `index.html` file is served up from the URL `http://mywe
|
|
|
180
200
|
- `route-path`: The path of the page. Supports custom URL parameters in the format `/org/:orgId/user/:userId`.
|
|
181
201
|
- `partial-route`: An optional attribute which, if specified, will allow the `route-path` to be matched partially from the start. This can be used to ignore the ending of a path which is not relevant to the page in order to avoid unnecessary re-renders.
|
|
182
202
|
- `redirect`: An optional path/route which this page should redirect to. Note that the content of this page will not be shown so it should always be empty.
|
|
183
|
-
- `auth-redirect`: An optional path/route
|
|
184
|
-
- `
|
|
185
|
-
- `hard-redirect`: An optional, additional attribute which can be specified alongside a `redirect`, `auth-redirect` or `
|
|
203
|
+
- `no-auth-redirect`: An optional alternative path/route to redirect to if the user lands on this page but they are not authenticated. If the user is authenticated, then the content of the template will be displayed as normal.
|
|
204
|
+
- `auth-redirect`: An optional alternative path/route to redirect to if the user lands on this page but they are already authenticated. If the user is not authenticated, then the content of the template will be displayed as normal.
|
|
205
|
+
- `hard-redirect`: An optional, additional attribute which can be specified alongside a `redirect`, `no-auth-redirect` or `auth-redirect` attribute to ensure that any redirect will change the URL in the address bar. Redirects are `soft` redirects by default; this means that they redirect the user to the target page but keep the current URL path unchanged.
|
|
186
206
|
|
|
187
207
|
### socket-provider
|
|
188
208
|
|
|
@@ -207,6 +227,7 @@ A Saasufy component which integrates with data from Saasufy is known as a `socke
|
|
|
207
227
|
|
|
208
228
|
- `url` (required): Specifies the URL for the Saasufy service to use as the data store for all components which are placed inside it.
|
|
209
229
|
- `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.
|
|
230
|
+
- `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.
|
|
210
231
|
|
|
211
232
|
### collection-browser
|
|
212
233
|
|
package/package.json
CHANGED
package/socket.js
CHANGED
|
@@ -26,9 +26,24 @@ export class SocketProvider extends HTMLElement {
|
|
|
26
26
|
connectedCallback() {
|
|
27
27
|
this.isReady = true;
|
|
28
28
|
this.getSocket();
|
|
29
|
+
let disableTabSync = this.hasAttribute('disable-tab-sync');
|
|
30
|
+
if (!disableTabSync) {
|
|
31
|
+
if (this.storageChangeWatcher) {
|
|
32
|
+
window.removeEventListener('storage', this.storageChangeWatcher);
|
|
33
|
+
}
|
|
34
|
+
this.storageChangeWatcher = (event) => {
|
|
35
|
+
if (event.storageArea === window.localStorage && event.key === this.saasufySocket.options.authTokenName) {
|
|
36
|
+
this.saasufySocket.reconnect();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
window.addEventListener('storage', this.storageChangeWatcher);
|
|
29
41
|
}
|
|
30
42
|
|
|
31
43
|
disconnectedCallback() {
|
|
44
|
+
if (this.storageChangeWatcher) {
|
|
45
|
+
window.removeEventListener('storage', this.storageChangeWatcher);
|
|
46
|
+
}
|
|
32
47
|
this.destroySocket();
|
|
33
48
|
}
|
|
34
49
|
|