laravel5-angular-material-starter: TypeError: $auth.isAuthenticated is not a function at redirectToLogin

  • I’m submitting a …
  • bug report
  • Provide information & explanation

Hi, i’m trying the framework and i have found a bug in the routes.run.js file.

If implements: “data: {auth: true}” in the routes.config.js in theory the event “redirectToLogin” must be fired, but when arrive to the funcion “$auth.isAuthenticated()” it crashed.

Attach a IMG: https://s32.postimg.org/s9gmn42th/Captura_de_pantalla_2016_07_12_a_las_16_25_27.png

I’ve change this code:

export function RoutesRun($state, $transitions) {
    'ngInject';

    let requiresAuthCriteria = {
        to: ($state) => $state.data && $state.data.auth
    };

    let redirectToLogin = ($auth) => {
        'ngInject';
        if (!$auth.isAuthenticated()) {
            return $state.target('app.login', undefined, {location: false});
        }
    };

    $transitions.onBefore(requiresAuthCriteria, redirectToLogin, {priority:10});

}

By this:

export function RoutesRun($state, $auth, $transitions) {
    'ngInject';

    let requiresAuthCriteria = {
        to: ($state) => $state.data && $state.data.auth
    };

    let redirectToLogin = () => {
        'ngInject';
        if (!$auth.isAuthenticated()) {
            return $state.target('app.login', undefined, {location: false});
        }
    };

    $transitions.onBefore(requiresAuthCriteria, redirectToLogin, {priority:10});

}

I’ve change the $auth var to inject instead the “redirectToLogin”.

And now (with my modifications) it works perfectly.

  • Laravel & Angular version: 3.2.1

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 6
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@jeslomo thanks again for reporting this I wanted to fix it in 3.3.0 but I just noticed that it has already been fixed before @flick36 thanks as well for your help 😄