Permalink
Browse files

feat(value-converters): move/rename/add valueConverters

isAuth(isAuthenicated):  isAuthenicated is optional. defaults to authService.authenticated
authenticated(): valueConverted added. returns authService.authenticated
made configurable which value converters should be global
  • Loading branch information...
doktordirk committed Jun 2, 2016
1 parent caf4a3b commit 4d2ee9365ff3fdcca48bac553d38170c42e274db
@@ -12,9 +12,9 @@ module.exports = {
source: appRoot + '**/*.js',
tsSource: [
appRoot + '**/*.js', // list files to parse for d.ts
'!' + appRoot + entryFileName // exclude entry file
'!' + appRoot + 'value-converters/*js' // exclude entry file
],
resources: 'authFilter.js', // relative to root, resources can not that easily be bundled into a single file (due to naming conventions)
resources: 'value-converters/*js', // relative to root, resources can not that easily be bundled into a single file (due to naming conventions)
html: appRoot + '**/*.html',
style: 'styles/**/*.css',
output: 'dist/',
@@ -6,7 +6,10 @@ import {AuthorizeStep} from './authorizeStep';
import {AuthenticateStep} from './authenticateStep';
import {BaseConfig} from './baseConfig';
import {FetchConfig} from './fetchClientConfig';
import './authFilter';
import * as LogManager from 'aurelia-logging';
// import to ensure value-converters get bundled
import './authFilterValueConverter';
import './authenticatedValueConverter';
/**
* Configure the plugin.
@@ -20,16 +23,19 @@ function configure(aurelia, config) {
PLATFORM.location.origin = PLATFORM.location.protocol + '//' + PLATFORM.location.hostname + (PLATFORM.location.port ? ':' + PLATFORM.location.port : '');
}
aurelia.globalResources('./authFilter');
const baseConfig = aurelia.container.get(BaseConfig);
if (typeof config === 'function') {
config(baseConfig);
} else if (typeof config === 'object') {
baseConfig.configure(config);
}
// after baseConfig was configured
for (let converter of baseConfig.globalValueConverters) {
aurelia.globalResources(`./${converter}`);
LogManager.getLogger('authentication').info(`Add globalResources value-converter: ${converter}`);
}
const fetchConfig = aurelia.container.get(FetchConfig);
const clientConfig = aurelia.container.get(Config);

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,19 @@
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())
* @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 => route.config.auth === isAuthenticated);
}
}
@@ -0,0 +1,17 @@
import {inject} from 'aurelia-dependency-injection';
import {AuthService} from './authService';
@inject(AuthService)
export class AuthenticatedValueConverter {
constructor(authService) {
this.authService = authService;
}
/**
* element toView predictator on authService.isAuthenticated()
* @return {Boolean} show/hide element
*/
toView() {
return this.authService.authenticated;
}
}
@@ -142,7 +142,10 @@ export class BaseConfig {
// The key used for storing the authentication response locally
storageKey = 'aurelia_authentication';
//OAuth provider specific related configuration
// List of value-converters to make global
globalValueConverters = ['authFilterValueConverter', 'authenticatedValueConverter'];
//OAuth provider specific related configuration
// ============================================
providers = {
facebook: {
@@ -52,11 +52,17 @@ describe('aurelia-authentication', function() {
it('Should call globalResources configuration to be passed as a function.', function() {
let container = new Container();
let globalResources = [];
configure({
container: container, globalResources: resource => {
expect(resource).toEqual('./authFilter');
globalResources.push(resource);
}
}, noop);
const expected = ['./authFilterValueConverter',
'./authenticatedValueConverter'];
expect(globalResources.toString()).toEqual(expected.toString());
});
it('Should allow configuration with a function.', function() {

0 comments on commit 4d2ee93

Please sign in to comment.