Skip to content
Snippets Groups Projects
login.js 706 B
Newer Older
  • Learn to ignore specific revisions
  • import Controller from '@ember/controller';
    
    Eugen Ciur's avatar
    Eugen Ciur committed
    import { service } from '@ember/service';
    
    import { action } from '@ember/object';
    import { tracked } from '@glimmer/tracking';
    
    Eugen Ciur's avatar
    Eugen Ciur committed
    
    
    export default class LoginController extends Controller {
      @tracked errorMessage;
      @service session;
    
    Eugen Ciur's avatar
    Eugen Ciur committed
      @service router;
    
      async authenticate(username, password) {
    
        try {
          await this.session.authenticate(
            'authenticator:auth-token',
    
            username,
    
            password
          );
        } catch (error) {
    
          this.errorMessage = "Invalid credentials";
    
    
        if (this.session.isAuthenticated) {
          // What to do with all this success?
    
    Eugen Ciur's avatar
    Eugen Ciur committed
          this.router.transitionTo('authenticated.index');