jeudi 3 mars 2016

Authentication with Ember.js 2.x

I'm new to ember.js and I find it pretty confusing to figure out which is a good way for authentication (version 2.x) since most of the examples on the web seem to be outdated. Also the documentation often doesn't come with easy to understand beginner examples.

Right now I'm following this tutorial. The initializer works apparently, I can also trigger the action login but then it gets stuck on the controller.get bit. The console spits out a TypeError: controller.get(...) is undefinedTypeError: controller.get(...) is undefined.

app/components/login-form

  ...
  actions: {                   
    login: function() {        
      var controller = this;   
      controller.get("session").login().then(function(admin) {
        // Persist your users details.  
      }, function() {
        // User rejected authentication request
      });
    } 
  }
  ...

app/templates/components/login-form

<form {{action 'login' on='submit'}}> 
  <div class="form-group">     
    <label for="email">Login</label>
    {{input value=email placeholder='Enter Login' class='form-control'}}
  </div>                       
  <div class="form-group">     
    <label for="password">Password</label> 
    {{input value=password placeholder='Enter Password' class='form-control' type='password'}}
  </div>                       
  <button type="submit" class="btn btn-default">Login</button>
</form>

app/templates/admin.hbs

<div class="page-header">      
  <h1>Login</h1>               
</div>
{{login-form}}  

I hope somebody can point me into the right direction to get this working. I'd also appreciate any general advice where to find good examples or explanations concerning the ember 2.x way of authentication.




Aucun commentaire:

Enregistrer un commentaire