stormpath / stormpath-sdk-angularjs

User Management for AngularJS (1.x) applications
http://docs.stormpath.com/angularjs/sdk/
Apache License 2.0
165 stars 58 forks source link

Infinite loop when accessing /login (using generator-angular-fullstack v3.7.5) #152

Open rondanal opened 8 years ago

rondanal commented 8 years ago

Hi,

Apologies for my ignorance here - I'm trying to follow the AngularJS + Yeoman Guide and am experiencing an infinite loop when building the login form section.

I created a new project using generator-angular-fullstack v3.7.5

The generated login.js file for the login route is:

'use strict';

angular.module('testApp')
  .config(function ($stateProvider) {
    $stateProvider
      .state('login', {
        url: '/login',
        template: '<login></login>'
      });
  });

login.controller.js:

'use strict';
(function(){

class LoginComponent {
  constructor() {
    this.message = 'Hello';
  }
}

angular.module('testApp')
  .component('login', {
    templateUrl: 'app/login/login.html',
    controller: LoginComponent
  });

})();

app.js:

'use strict';

angular.module('testApp', ['testApp.constants', 'ngCookies', 'ngResource', 'ngSanitize',
    'btford.socket-io', 'ui.router', 'ui.bootstrap', 'stormpath', 'stormpath.templates'
  ])
  .config(function($urlRouterProvider, $locationProvider) {
    $urlRouterProvider.otherwise('/');

    $locationProvider.html5Mode(true);
  })

  .run(function($stormpath){
    $stormpath.uiRouter({
      loginState: 'login', 
      defaultPostLoginState: 'main' 
    });
  });

I see that these differ from the dashboard-app example code, which doesn't use the component sytnax. When I run the project and visit `/login' I see an infinite loop in the browser. I've followed all of the steps up to https://docs.stormpath.com/angularjs/guide/register.html#create-the-registration-form verbatim.

Does the most recent version of stormpath-sdk-angularjs support the component style generated here (by generator-angular-fullstack v3.7.5)? If not, is there a easy way to fix the generated code, or would I need to use an older version of generator-angular-fullstack (the tutorial does not specify a version as far as I can tell)?

Thanks

robertjd commented 8 years ago

Hello @rondanal , thanks for the report. Can you take a look at #147 to see if this is the same issue that you are having? Thanks!

rondanal commented 8 years ago

Hi @robertjd , thanks for your response.

It looks like it wasn't related to #147, but is now working after modifying a few lines of code in the generator-angular-fullstack v3.7.5 server files.

The first issue seemed to be that I inited the Stormpath middleware after require('./routes').default(app);. I moved this line after the SP init, and also changed the init code from:

app.use(ExpressStormpath.init(app,{
  website: true,
  web: {
    spaRoot: path.join(__dirname, '..','client','index.html')
  }
}));

to the snippet from the dashboard-app example:

app.use(ExpressStormpath.init(app,{
  web: {
    produces: ['application/json'],
    spa: {
      enabled: true,
      view: app.get('appPath')
    }
  }
}));

I also had to modify appPath in the expres.js config file to match the dashboard-app example code. Lastly, in routes.js I modified the now default:

  app.route('/*')
    .get((req, res) => {
      res.sendFile(path.resolve(app.get('appPath') + '/index.html'));
    });

to:

app.route('/*')
    .get((req, res) => {
      res.sendFile(path.resolve(app.get('appPath')));
    });

Everything is now running smoothly. Thanks!