fnakstad / angular-client-side-auth

One way to implement authentication/authorization in Angular applications
http://angular-client-side-auth.herokuapp.com/
MIT License
1.63k stars 346 forks source link

AngularAMD #76

Closed kvanbere closed 10 years ago

kvanbere commented 10 years ago

How do we do this with something like angularAMD where app is undefined at configuration time?

fnakstad commented 10 years ago

I'm not familiar with angularAMD, but can't you just get a reference to your app instance through the Angular dependency injector? Like angular.module('module-name'); If not, what is restricting you from doing that?

kvanbere commented 10 years ago

Say I setup a file to be async loaded and applied to app which hooks the state change, ie; run.js:

define(["app"], function(app) {
    'use strict';

    app.run(["$rootScope", function($rootScope) {
        $rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams) {
            alert("state changed");
        });
    }]);

});

When I add it as an application dependency, app is undefined because the dependencies have to be completely loaded before the app is setup.

So you end up getting something like:

TypeError: app is undefined run.js:5

If you refactor that to have the app.js pull in the Auth service instead, then the Auth service needs a reference to app where the same undefined thing happens.

Sorry, this is really an AMD thing.

fnakstad commented 10 years ago

Hmmm, sorry I can't be of more help, but I'm not familiar enough with AMD to give you a good answer. Is there perhaps an event that is fired when all dependencies have been loaded that you can hook up to?

kvanbere commented 10 years ago

The nature of AMD and html5 means you can never be sure when it's done loading dependencies. I'll be having another crack at it soon. If I get it working I'll make sure to put a solution here.

fnakstad commented 10 years ago

That sounds good. Thanks!