Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4840

Uncaught (in promise) TypeError: Class constructor Class cannot be invoked without 'new'

$
0
0

I’m getting the following error in the console of the browser, when trying to access my route “login”:

Uncaught (in promise) TypeError: Class constructor Class cannot be invoked without 'new'
at login.js:15
at Array.reduce (<anonymous>)
at _applyDecoratedDescriptor (login.js:15)
at Module.callback (login.js:31)
at Module.exports (loader.js:106)
at requireModule (loader.js:27)
at Class._extractDefaultExport (index.js:463)
at Class.resolveOther (index.js:123)
at Class.resolve (index.js:186)
at resolve (index.js:1223)

This is the code of my route:

import Route from '@ember/routing/route';
import inject from '@ember/service';

export default class LoginRoute extends Route {
  @inject session;

  // eslint-disable-next-line no-unused-vars
  beforeModel(transition) {
    this.session.prohibitAuthentication('index');
  }
}

Controller:

import Controller from '@ember/controller';
import inject from '@ember/service';
import action from '@ember/object';
import ENV from 'Project/config/environment';

export default class LoginController extends Controller {
  @inject session;

  @action
  async authenticate() {
    try {
      this.session.authenticate('authenticator:cookie');
    } catch(error) {
      console.log(error.error || error);
      window.location.url = ENV.SERVER_URL;
    }

    if(this.session.isAuthenticated) {
      console.log("AUTHENTICATED!! FINALLY!");
      //this.transitionToRoute('index');
    }
  }
}

As I’m also using ember-simple-auth for authentication, here the code my custom authenticator:

import Base from 'ember-simple-auth/authenticators/base'
import ENV from 'Project/config/environment';
import RSVP from 'rsvp';

export default class CookieAuthenticator extends Base {
  loginUrl = ENV.SERVER_URL;

  // eslint-disable-next-line no-unused-vars
  restore(data) {
    return RSVP.resolve();
  }

  // eslint-disable-next-line no-unused-vars
  authenticate(options) {
    return fetch(ENV.SERVER_URL + "authState", {credentials: "include"})
      .then(resp => resp.text())
      .then(text => {
        if(text === "true") {
          return Promise.resolve.bind(Promise);
        } else {
          return Promise.reject.bind(Promise);
        }
      })
      .catch(error => {
        console.log(error.error || error);
      });
  }

  // eslint-disable-next-line no-unused-vars
  invalidate(data) {
    return fetch(ENV.SERVER_URL + "logout", { credentials: "include" });
  }
}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4840

Trending Articles