身份验证未定义 - ui-router &授权0 [英] auth is undefined - ui-router & Auth0

查看:30
本文介绍了身份验证未定义 - ui-router &授权0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 auth0 与 ui-router 一起使用.加载默认路由后,我可以看到 auth 对象已定义并包含方法.当我尝试访问控制器内的值时出现未定义错误.将这个对象作为可重用对象与我的控制器共享的最佳方式是什么?

I'm using auth0 with ui-router. When the default route is loaded I can see the auth object is defined and contains methods. I get an undefined error when I try to access the value inside a controller. What's the best way of sharing this object with my controllers as as a reusable object?

!-- 控制器

module.controller('login', ['$scope', function($scope,auth) {

!---

}).run(function($rootScope, auth, store, jwtHelper, $state, $stateParams) {

    $rootScope.$on('$locationChangeStart', function() {
        if (!auth.isAuthenticated) {
            var token = store.get('token');
            if (token) {
                if (!jwtHelper.isTokenExpired(token)) {
                    auth.authenticate(store.get('profile'), token);
                } else {
                    $state.go('login');
                }
            }
        }

    });

});

推荐答案

当您使用显式注解(正如您应该的那样)时,您需要显式定义所有参数.因此,将 'auth' 添加到该列表中:

When you use explicit annotation (as you should), you need to explicitly define all the parameters. So, add 'auth' to that list:

module.controller('login', ['$scope', 'auth', function($scope, auth) {
..}]);

这篇关于身份验证未定义 - ui-router &授权0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆