AUTH是不确定的 - UI路由器和放大器; Auth0 [英] auth is undefined - ui-router & Auth0

查看:137
本文介绍了AUTH是不确定的 - UI路由器和放大器; Auth0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用auth0与UI的路由器。当默认路由被加载,我可以看到auth对象定义和包含的方法。我得到一个未定义的错误,当我尝试访问控制器内的值。什么是共享我的控制器此对象作为一个可重用的对象,最好的办法?

! - 控制器

  module.controller('登陆',['$范围',函数($范围,AUTH){

! -

 })。运行(函数($ rootScope,身份验证,存储,jwtHelper,$状态,$ stateParams){    $ rootScope。在$('$ locationChangeStart',函数(){
        如果(!auth.isAuthenticated){
            VAR令牌= store.get('令牌');
            如果(标记){
                如果(!jwtHelper.isTokenExpired(令牌)){
                    auth.authenticate(store.get(个人资料),令牌);
                }其他{
                    $ state.go('登录');
                }
            }
        }    });});


解决方案

当您使用显式的标注(如你应该),你需要明确定义所有参数。因此,添加'权威性'到列表:

  module.controller('登陆',['$范围,权威性,函数($范围,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?

!-- controller

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');
                }
            }
        }

    });

});

解决方案

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) {
..}]);

这篇关于AUTH是不确定的 - UI路由器和放大器; Auth0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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