karlhepler / angular-middleware

Laravel-like middleware for Angular ui.router and ngRoute
MIT License
33 stars 4 forks source link

plugins.js:2 TypeError: Cannot read property 'next' of undefined #7

Open stefensuhat opened 7 years ago

stefensuhat commented 7 years ago

Hi,

I always get those error when setup the middleware. here is my code:

 $middlewareProvider.map({ 

            'check-token': ['Auth', (Auth) => {
                const request = this;
                Auth.get({ url: 'check-token' }, response => {
                    if (response) {
                        return request.next();
                    }
                });
            }]
        });
karlhepler commented 7 years ago

I haven't tried it yet, but it looks like you are using those new fancy arrow functions, which implicitly binds "this" to the parent object. I think, but I'm not sure without checking, that "this" is actually referencing the map object and not the request. Give it a try without the arrow functions and let me know. I'll be happy to look into it more if that's not the case.