jeudi 14 juillet 2016

Ember Js not authenticating with Devise

My ember js app is not authenticating the session correctly. It will post to the data base correctly but will not authenticate the session. I am using rails 4, ember-simple-auth1.1.0 and ember 2.5

Rails Session Controller

class SessionsController < Devise::SessionsController
  respond_to :html, :json

def create
 super do |user|
  if request.format.json?
     data = {
      token: user.authentication_token,
      email: user.email
    }
    render json: data, status: 201  and return
    end
  end
 end
end

Ember login controller

import Ember from 'ember';

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

  actions: {
    authenticate() {
      let { identification, password } = this.getProperties('identification', 'password');
      this.get('session').authenticate('authenticator:devise', identification, password)
      .then(() =>{
        this.transitionToRoute('posts')
      })
      .catch((reason) => {
        this.set('errorMessage', reason.error || reason);
      });
    }
  }
});

Login.hbs


  


login-form.hbs

    <form >
      <div class="form-group">
        <label for="identification">Login</label>
        
      </div>

    <div class="form-group">
      <label for="password">Password</label>
      
    </div>

      <button class="btn btn-default" type="submit">Login</button>
    </form>


    
      
    

The entire project can be found at http://ift.tt/29TwMP7




Aucun commentaire:

Enregistrer un commentaire