Ember CLI - Simple Auth - Custom Authenticator not automatically registering

313 Views Asked by At

I'm attempting to setup a custom authenticator with ember simple auth. I'm using Ember CLI and according to the Simple Auth ReadMe on GitHub it states. Note that when you're not using Ember CLI the authenticator will not be registered with the container automatically and you need to do that in an initializer.

It does not state where you need to put your authenticator (or authorizer for that matter) in your directory structure in order for it to be registered by Ember CLI automatically. After creating my file in app/authenticators/custom.js (as shown in the examples of the read me) I expected it to be registered with the container. Looking in Ember Inspector it's no where to be found.

Does anyone have any insight into this? Where are these files meant to be placed?

Please ask if any additional information is needed.

Ember: 1.7.0
Ember Data: 1.0.0-beta.10
Ember Simple Auth: 0.7.1
3

There are 3 best solutions below

0
On

Make sure you have your initializer in /app/initializers/. Initializers in this directory are automatically set up by ember-cli.

// app/initializers/authentication.js
import CustomAuthenticator from '../authenticators/custom';

export default {
  name:       'authentication',
  before:     'simple-auth',
  initialize: function(container, application) {
    container.register('authenticator:custom', CustomAuthenticator);
  }
};
0
On

The latest version of Ember CLI should actually auto-register the authenticator - make sure you're using that (you probably aren't as you're still at Ember 1.7.0). That should solve it.

2
On

I am getting the same issue and I have Ember 1.8.1

Error is: Uncaught ReferenceError: CustomAuthenticator is not defined in file app/authenticators/custom.js

I needed to add an initializer and change the code found in the docs to this below, and it works

import Base from 'simple-auth/authenticators/base';

var CustomAuthenticator = Base.extend({
  restore: function(data) {
  },
  authenticate: function(options) {
  },
  invalidate: function(data) {
  }
});

export default CustomAuthenticator;