Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
fix(ValueConverters): bring back old authFilter version since new one…
Browse files Browse the repository at this point in the history
… can't be auto bundled
  • Loading branch information
doktordirk committed Jun 4, 2016
1 parent fc9713a commit a66394d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/aurelia-authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {FetchConfig} from './fetchClientConfig';
import * as LogManager from 'aurelia-logging';
// import to ensure value-converters get bundled
import './authFilterValueConverter';
import './authenticatedValueConverter';

/**
* Configure the plugin.
Expand Down
16 changes: 4 additions & 12 deletions src/authFilterValueConverter.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import {inject} from 'aurelia-dependency-injection';
import {AuthService} from './authService';

@inject(AuthService)
export class AuthFilterValueConverter {
constructor(authService) {
this.authService = authService;
}

/**
* route toView predictator on route.config.auth === (parameter || authService.isAuthenticated())
* route toView predictator on route.config.auth === isAuthenticated
* @param {RouteConfig} routes the routes array to convert
* @param {[Boolean]} [isAuthenticated] optional isAuthenticated value. default: this.authService.authenticated
* @param {Boolean} isAuthenticated authentication status
* @return {Boolean} show/hide element
*/
toView(routes, isAuthenticated = this.authService.authenticated) {
return routes.filter(route => route.config.auth === isAuthenticated);
toView(routes, isAuthenticated) {
return routes.filter(route => typeof route.config.auth !== 'boolean' || route.config.auth === isAuthenticated);
}
}
19 changes: 19 additions & 0 deletions src/authenticatedFilterValueConverter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {inject} from 'aurelia-dependency-injection';
import {AuthService} from './aurelia-authentication';

@inject(AuthService)
export class AuthenticatedFilterValueConverter {
constructor(authService) {
this.authService = authService;
}

/**
* route toView predictator on route.config.auth === (parameter || authService.isAuthenticated())
* @param {RouteConfig} routes the routes array to convert
* @param {[Boolean]} [isAuthenticated] optional isAuthenticated value. default: this.authService.authenticated
* @return {Boolean} show/hide element
*/
toView(routes, isAuthenticated = this.authService.authenticated) {
return routes.filter(route => typeof route.config.auth !== 'boolean' || route.config.auth === isAuthenticated);
}
}
2 changes: 1 addition & 1 deletion src/baseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class BaseConfig {
storageKey = 'aurelia_authentication';

// List of value-converters to make global
globalValueConverters = ['authFilterValueConverter', 'authenticatedValueConverter'];
globalValueConverters = ['authFilterValueConverter', 'authenticatedFilterValueConverter', 'authenticatedValueConverter'];

//OAuth provider specific related configuration
// ============================================
Expand Down

0 comments on commit a66394d

Please sign in to comment.