mercredi 1 mars 2017

Implementing user login and registration using ember-simple-auth

I have an API with two URLs:

  1. /api/auth/login
  2. /api/auth/signup

I am able to implement user login using ember-simple-auth and ember-simple-auth-token with the following code:

components/login-form/template.hbs


  
  
  

  
    
      <strong>Error: </strong> 
    
  

  


components/login-form/component.js

import Ember from 'ember';

export default Ember.Component.extend({
  session: Ember.inject.service(),

  actions: {
    authenticate() {
      var credentials = this.getProperties('identification', 'password', 'secret'),
      authenticator = 'authenticator:token';

      console.log(this.get('session').get('isAuthenticated'));

      this.get('session').authenticate(authenticator, credentials).catch((reason) => {
            this.set('errorMessage', JSON.stringify(reason.error.message));
          });
        }
      }
});

config/enviroment.js

  ENV['ember-simple-auth'] = {
    authorizer: 'authorizer:token'
  };

  ENV['ember-simple-auth-token'] = {
    refreshAccessTokens: true,
    timeFactor: 1000,
    refreshLeeway: 300,
    identificationField: 'name',
    passwordField: 'password',
    secretField: 'secret',
    serverTokenEndpoint: 'http://ift.tt/2mv7NJV',
    tokenPropertyName: 'token',
    authorizationPrefix: 'Bearer ',
    authorizationHeaderName: 'Authorization',
    headers: {},
  };

I can't seem to find any docs online that implement both user registration and login that I can follow properly. Most of the tutorials I find have user login/registration using the same authenticator and same URL (/api/auth/user) but in my case I have two URLs one for each action.

What would be the proper way to handle this situation?

Thanks.




Aucun commentaire:

Enregistrer un commentaire