Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "aurelia-router in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'aurelia-router' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

it(`should redirect to ${unauthRedirectRoute} if user is null`, async () => {
        // arrange
        (userManager.getUser).returns(null);
        // act
        await authorizationStep.run(navigationInstruction, next);
        // assert
        sinon.assert.calledWith(next.cancel, new Redirect(unauthRedirectRoute));
      });
it(`redirect should be to the unauthorized route with original URL as LoginRedirect parameter`, async () => {
        // arrange
        (userManager.getUser).returns(null);
        // act
        await authorizationStep.run(navigationInstruction, next);
        // assert
        sinon.assert.calledWith(next.cancel, new Redirect(expectedRedirect));
      });
canActivate() {
		// Don't show as router-view if sidebar is not hidden
		return window.innerWidth < config.SCREEN_SMALL_BREAKPOINT_PX || new Redirect('');
	}
// TODO: Make this open for extension,
    // so that user-land can configure multiple, arbitrary roles.
    if (this.requiresRole(navigationInstruction, OpenIdConnectRoles.Authenticated)) {
      if (user === null || user.expired) {
        this.logger.debug('Requires authenticated role.');

        // capture the URL to which the user was originally navigating
        // include that URL in a query string parameter on the redirect
        let loginRedirect = navigationInstruction.fragment;
        if (navigationInstruction.queryString && navigationInstruction.queryString.length) {
          loginRedirect += `?${navigationInstruction.queryString}`;
        }
        const loginRedirectValue = encodeURIComponent(loginRedirect);
        const queryString = `?${LoginRedirectKey}=${loginRedirectValue}`;
        const redirect = new Redirect(this.configuration.unauthorizedRedirectRoute + queryString);

        return next.cancel(redirect);
      }
    }

    return next();
  }
run(routingContext, next) {
    // Check if the route has an "auth" key
    // The reason for using `nextInstructions` is because this includes child routes.
    if (routingContext.getAllInstructions()
      .some(i => i.config.auth)) {
      if (!this.appState.Authenticated) {
        this.logger.warn('Not authenticated');
        let url = routingContext.router.generate('login', { status: 401 });
        this.appState.Authenticated = false;
        this.appState.session('AppCurrentRoute', [routingContext.config.route, routingContext.params]);
        this.appState.session('AppCurrentFragment', routingContext.fragment);
        return next.reject(new Redirect(url));
      }
    }

    return next();
  }
}
run(routingContext, next) {
    // Check if the route has an "auth" key
    // The reason for using `nextInstructions` is because this includes child routes.
    if (routingContext.getAllInstructions()
      .some(i => i.config.auth)) {
      if (!this.appState.Authenticated) {
        this.logger.warn('Not authenticated');
        let url = routingContext.router.generate('login', { status: 401 });
        this.appState.Authenticated = false;
        this.appState.session('AppCurrentRoute', [routingContext.config.route, routingContext.params]);
        this.appState.session('AppCurrentFragment', routingContext.fragment);
        return next.reject(new Redirect(url));
      }
    }

    return next();
  }
}
run(routingContext, next) {
    // Check if the route has an "auth" key
    // The reason for using `nextInstructions` is because this includes child routes.
    if (routingContext.getAllInstructions()
      .some(i => i.config.auth)) {
      if (!this.appState.IsAuthenticated) {
        this.logger.warn('Not authenticated');
        let url = routingContext.router.generate('login', { status: 401 });
        this.appState.IsAuthenticated = false;
        this.appState.session('AppCurrentRoute', [routingContext.config.route, routingContext.params]);
        this.appState.session('AppCurrentFragment', routingContext.fragment);
        return next.reject(new Redirect(url));
      }
    }

    return next();
  }
}
resolve(false);
          });
        }
        //#endregion
    });

    const result: boolean = await _modal;

    // TODO: Extract Business Rule
    if (result === false) {
      /*
       * As suggested in https://github.com/aurelia/router/issues/302, we use
       * the router directly to navigate back, which results in staying on this
       * component-- and this is the desired behaviour.
       */
      return new Redirect(this._router.currentInstruction.fragment, {trigger: false, replace: false});
    }
  }
run(routingContext, next) {
    var isLoggedIn = this.auth.isAuthenticated();
    var loginRoute = this.auth.getLoginRoute();

    if (routingContext.getAllInstructions().some(i => i.config.auth)) {
      if (!isLoggedIn) {
        this.auth.setInitialUrl(window.location.href);
        return next.cancel(new Redirect(loginRoute));
      }
    } else if (isLoggedIn && routingContext.getAllInstructions().some(i => i.fragment == loginRoute)) {
      var loginRedirect = this.auth.getLoginRedirect();
      return next.cancel(new Redirect(loginRedirect));
    }

    return next();
  }
}
run(routingContext, next) {
    var isLoggedIn = this.auth.isAuthenticated();
    var loginRoute = this.auth.getLoginRoute();

    if (routingContext.getAllInstructions().some(i => i.config.auth)) {
      if (!isLoggedIn) {
        this.auth.setInitialUrl(window.location.href);
        return next.cancel(new Redirect(loginRoute));
      }
    } else if (isLoggedIn && routingContext.getAllInstructions().some(i => i.fragment == loginRoute)) {
      var loginRedirect = this.auth.getLoginRedirect();
      return next.cancel(new Redirect(loginRedirect));
    }

    return next();
  }
}

Is your System Free of Underlying Vulnerabilities?
Find Out Now