paulvanbladel / aurelia-auth

:key: Authentication plugin for aurelia
200 stars 74 forks source link

import {Authentication} from 'aurelia-auth' #137

Open jonathaneckman opened 8 years ago

jonathaneckman commented 8 years ago

Trying to do this: import {Authentication} from 'aurelia-auth'; will give the following error:

Error: key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?

paulvanbladel commented 8 years ago

when you look to the 'index' file (aurelia-auth.js) you will see that the Authentication class is not exported. I guess that's the reason why you can't import it, no?

import {AuthService} from './auth-service';
import {AuthorizeStep} from './authorize-step';
import {FetchConfig} from './auth-fetch-config';
import {BaseConfig} from './base-config';
import {AuthFilterValueConverter} from './auth-filter';

export function configure(aurelia, configCallback) {
  aurelia.globalResources('./auth-filter');

  let baseConfig = aurelia.container.get(BaseConfig);
  if (configCallback !== undefined && typeof(configCallback) === 'function') {
    configCallback(baseConfig);
  }
}

export {
  AuthFilterValueConverter,
  AuthService,
  AuthorizeStep,
  BaseConfig,
  FetchConfig
};
davidpurkiss commented 7 years ago

Having a similar issue. The reason I am trying to import Authentication is because this is where setToken() is. How would one go about "Supplying token programmatically" without this?

davidpurkiss commented 7 years ago

Oh, never mind. I got it working with the following.

this.authService.auth.setToken(token, redirect);

ShaunVanDyk commented 7 years ago

Shouldn't Authentication be exported as part of the node_module though? The example in the docs under "What exactly is 'configured' on the Http Client and can we have multiple endpoints?" point to using the auth.TokenInterceptor so that you can configure the rest of the settings yourself, however because Authentication isn't exported we can't import { Authentication } from 'aurelia-auth'. (On that note the documentation is wrong as well as it injects AuthService into auth which doesn't contain a TokenInterceptor method).

The sample app works fine because it is using all of the files from the library in a local context, however when using the library via npm this just doesn't work.