saasufy-components 2.6.0 → 2.6.2

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 (2) hide show
  1. package/app-router.js +42 -39
  2. package/package.json +1 -1
package/app-router.js CHANGED
@@ -153,16 +153,52 @@ export class AppRouter extends SocketConsumer {
153
153
  let maxRedirects = Number(this.getAttribute('max-redirects') || DEFAULT_MAX_REDIRECTS);
154
154
 
155
155
  let redirectCount;
156
- for (redirectCount = 0; redirectCount < maxRedirects; redirectCount++) {
156
+ for (redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
157
+ let authRedirect = this.socket && this.socket.authState === 'authenticated' ?
158
+ pageTemplate.getAttribute('auth-redirect') : null;
159
+ let noAuthRedirect = this.socket && this.socket.authState !== 'authenticated' ?
160
+ pageTemplate.getAttribute('no-auth-redirect') : null;
161
+
162
+ if (
163
+ (authRedirect != null || noAuthRedirect != null) &&
164
+ this.socket &&
165
+ this.socket.authState !== 'authenticated' &&
166
+ this.socket.state !== this.socket.OPEN
167
+ ) {
168
+ return;
169
+ }
170
+
157
171
  let redirect = pageTemplate.getAttribute('redirect');
158
- let noAuthRedirect = pageTemplate.getAttribute('no-auth-redirect');
159
- let authRedirect = pageTemplate.getAttribute('auth-redirect');
160
172
 
161
- if (!redirect && !noAuthRedirect && !authRedirect) break;
173
+ if (authRedirect == null && noAuthRedirect == null && redirect == null) break;
162
174
 
163
175
  let hardRedirect = pageTemplate.hasAttribute('hard-redirect');
164
176
 
165
- if (redirect) {
177
+ if (authRedirect != null) {
178
+ if (hardRedirect) {
179
+ location.hash = authRedirect;
180
+ return;
181
+ }
182
+ routeArgs = this.computeRouteArgs(pagePath, regExp, params);
183
+ pagePath = this.substituteRouteAgs(authRedirect, routeArgs);
184
+ let result = this.getMatchingPage(pagePath, 'auth-redirect');
185
+ pageTemplate = result.pageTemplate;
186
+ route = result.route;
187
+ regExp = result.regExp;
188
+ params = result.params;
189
+ } else if (noAuthRedirect != null) {
190
+ if (hardRedirect) {
191
+ location.hash = noAuthRedirect;
192
+ return;
193
+ }
194
+ routeArgs = this.computeRouteArgs(pagePath, regExp, params);
195
+ pagePath = this.substituteRouteAgs(noAuthRedirect, routeArgs);
196
+ let result = this.getMatchingPage(pagePath, 'no-auth-redirect');
197
+ pageTemplate = result.pageTemplate;
198
+ route = result.route;
199
+ regExp = result.regExp;
200
+ params = result.params;
201
+ } else {
166
202
  if (hardRedirect) {
167
203
  location.hash = redirect;
168
204
  return;
@@ -174,43 +210,10 @@ export class AppRouter extends SocketConsumer {
174
210
  route = result.route;
175
211
  regExp = result.regExp;
176
212
  params = result.params;
177
- } else {
178
- if (this.socket && (authRedirect || noAuthRedirect)) {
179
- if (this.socket.authState === 'authenticated') {
180
- if (authRedirect) {
181
- if (hardRedirect) {
182
- location.hash = authRedirect;
183
- return;
184
- }
185
- routeArgs = this.computeRouteArgs(pagePath, regExp, params);
186
- pagePath = this.substituteRouteAgs(authRedirect, routeArgs);
187
- let result = this.getMatchingPage(pagePath, 'auth-redirect');
188
- pageTemplate = result.pageTemplate;
189
- route = result.route;
190
- regExp = result.regExp;
191
- params = result.params;
192
- }
193
- } else {
194
- if (this.socket.state !== this.socket.OPEN) return;
195
- if (noAuthRedirect) {
196
- if (hardRedirect) {
197
- location.hash = noAuthRedirect;
198
- return;
199
- }
200
- routeArgs = this.computeRouteArgs(pagePath, regExp, params);
201
- pagePath = this.substituteRouteAgs(noAuthRedirect, routeArgs);
202
- let result = this.getMatchingPage(pagePath, 'no-auth-redirect');
203
- pageTemplate = result.pageTemplate;
204
- route = result.route;
205
- regExp = result.regExp;
206
- params = result.params;
207
- }
208
- }
209
- }
210
213
  }
211
214
  }
212
215
 
213
- if (redirectCount >= maxRedirects) {
216
+ if (redirectCount > maxRedirects) {
214
217
  throw new Error(
215
218
  `The number of redirects exceeded the maximum amount of ${maxRedirects}`
216
219
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "2.6.0",
3
+ "version": "2.6.2",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {