Auth0 is not a consutructor语言 - AngularJS and auth0



我只是按照本指南将auth0(有史以来第一次)添加到我的angularJS应用程序中。 单击登录按钮并输入我的凭据后,屏幕将重新加载(使用包含令牌和 ID 的 URL),然后再次重新加载,引发以下异常:

TypeError: Auth0 is not a constructor
    at angular-lock.js:77
    at Scope.$broadcast (angular.js:17767)
    at angular.js:13523
    at Scope.$eval (angular.js:17444)
    at Scope.$digest (angular.js:17257)
    at Scope.$apply (angular.js:17552)
    at bootstrapApply (angular.js:1754)
    at Object.invoke (angular.js:4709)
    at doBootstrap (angular.js:1752)
    at bootstrap (angular.js:1772)
    at angularInit (angular.js:1657)
    at HTMLDocument.<anonymous> (angular.js:31468)
    at j (jquery-2.1.1.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-2.1.1.min.js:2)
    at Function.ready (jquery-2.1.1.min.js:2)
    at HTMLDocument.I (jquery-2.1.1.min.js:2)

Angular-lock.js:77 具有以下代码:

lock.interceptHash = function() {
        $rootScope.$on('$locationChangeStart', function(event, location) {
          if (/id_token=/.test(location) || /error=/.test(location)) {
            var auth0 = new Auth0(credentials);

其中if语句是第 77 行。 有谁知道是什么原因造成的? 这是我对各种 auth0 组件的代码:

登录.js

.controller('LoginCtrl', function (authService ,$scope, $rootScope, $state, $log, ServerRequest, $localStorage, $sessionStorage, uiGridConstants, $interval) {
            var vm = this, c = console;
            c.log('hit login controller');
            vm.authService = authService;

应用运行.js

run.$inject = ['$rootScope', 'authService', 'lock', 'authManager'];
  function run($rootScope, authService, lock, authManager) {
    // // Put the authService on $rootScope so its methods
    // // can be accessed from the nav bar
     $rootScope.authService = authService;
    //
    // // Register the authentication listener that is
    // // set up in auth.service.js
     authService.registerAuthenticationListener();
    //
    // // Register the synchronous hash parser
    // // when using UI Router
    lock.interceptHash();
    authManager.checkAuthOnRefresh();
  }

身份验证服务.js

function authService(lock, authManager, $state) {
    function login() {
      lock.show();
    }
    function logout() {
      localStorage.removeItem('id_token');
      authManager.unauthenticate();
      $state.go('login');
    }
    // Set up the logic for when a user authenticates
    // This method is called from app.run.js
    function registerAuthenticationListener() {
      lock.on('authenticated', function (authResult) {
        localStorage.setItem('id_token', authResult.idToken);
        authManager.authenticate();
        $state.go('list.grid');
      });
    }
    return {
      login: login,
      logout: logout,
      registerAuthenticationListener: registerAuthenticationListener
    }
  }

此外(我真的不知道它是否相关),注销后,我仍然可以访问我的所有应用程序。我是这方面的新手,所以任何方向都将不胜感激。

有同样的问题。文档不是最新的。通过在 bower.json 中强制"auth0-lock": "10.2.2"来修复该特定问题。

  1. 删除/bower_components 文件夹
  2. 编辑 bower.json 以使用 auth0-lock 版本 10.2.2
  3. 从终端$ bower install
  4. 重新加载应用程序

我运行的实际解决方案:

"auth0-lock": "^10.11.0",
"angular-lock": "^1.0.5",
"auth0.js": "7.6.1"

我不得不单独安装 Auth0.js v7 作为依赖项; v8 有问题。现在 Auth0 锁定小部件对我有用。

此外,Auth0 为我提供了这个存储库,他们在其中使用 Auth0-Lock 10.11.0 和 Auth0.js 8.0.4:

https://github.com/auth0-samples/auth0-angularjs-samples/tree/master/01-Basic-Login

最新更新