Auth0不是一个使用者 - AngularJS和auth0

时间:2017-01-17 22:14:58

标签: angularjs auth0

我只是按照this guide将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组件的代码:

login.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;

app.run.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();
  }

auth.service.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
    }
  }

另外(我真的不知道它是否相关),当我注销时,我仍然可以访问我的所有应用程序。我是新手,所以任何方向都会受到高度赞赏。

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

我的实际解决方案:

Tue Jan 31 17:38:10 +0000 2017 -> 31/01/2017 or 31-01-2017

我必须分别安装Auth0.js v7作为依赖项; v8有问题。现在,Auth0 Lock小部件适用于我。

此外,Auth0为我提供了这个回购,他们使用的是Auth0-Lock 10.11.0和Auth0.js 8.0.4:

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