gpt4 book ai didi

auth0 - 如何避免/修复 "Auth0Lock is not defined"异常

转载 作者:行者123 更新时间:2023-12-04 14:55:51 24 4
gpt4 key购买 nike

我正在尝试使用 Auth0 进行社交登录,但我不断收到 undefined reference 的异常。

这是身份验证服务

import { Injectable }      from '@angular/core';
import { tokenNotExpired } from 'angular2-jwt';

// Avoid name not found warnings
declare var Auth0Lock: any;

@Injectable()
export class AuthService {
// Configure Auth0

lock = new Auth0Lock('I have set the ID correctly here', 'and the domain as well', {});

constructor() {
// Add callback for lock `authenticated` event
this.lock.on("authenticated", (authResult) => {
localStorage.setItem('id_token', authResult.idToken);
});
}

public login() {
// Call the show method to display the widget.
this.lock.show();
};

public authenticated() {
// Check if there's an unexpired JWT
// This searches for an item in localStorage with key == 'id_token'
return tokenNotExpired();
};

public logout() {
// Remove token from localStorage
localStorage.removeItem('id_token');
};
}

我注入(inject)了服务并配置了提供程序。一切都已正确连接,但找不到 Auth0Lock即使定义了。
每次达到 lock = new Auth0Lock('ID', 'DOMAIN', {});它爆炸了。

最佳答案

我替换了declare var Auth0Lock: any;const Auth0Lock = require('auth0-lock').default;这解决了问题。

关于auth0 - 如何避免/修复 "Auth0Lock is not defined"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40957465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com