【发布时间】:2019-11-23 09:23:47
【问题描述】:
我假设我的身份验证服务未能加载导致错误的配置文件。 我正在关注关于 AUTH0 的教程。这里是链接 https://auth0.com/blog/real-world-angular-series-part-2/。 我必须从 env.config.ts 导入我的身份验证服务将使用的文件。这里是代码 env.config.ts
const _isDev = window.location.port.indexOf('4200') > -1;
const getHost = () => {
const protocol = window.location.protocol;
const host = window.location.host;
return `${protocol}//${host}`;
};
const apiURI = _isDev ? 'http://localhost:8083/api/' : `/api/`;
export const ENV = {
BASE_URI: getHost(),
BASE_API: apiURI
};
这是教程中的引述“此代码检测主机环境并设置应用程序的基本 URI 和基本 API URI。我们将在需要检测和使用这些 URI 的任何地方导入此 ENV 配置。” 这个env文件被导入到auth0需要的文件中, 这是我的 auth.config.ts
的 sn-pimport { ENV } from './../core/env.config';
interface AuthConfig {
CLIENT_ID: string;
CLIENT_DOMAIN: string;
AUDIENCE: string;
REDIRECT: string;
SCOPE: string;
NAMESPACE: string;
};
export const AUTH_CONFIG: AuthConfig = {
CLIENT_ID: '[xxx]',
CLIENT_DOMAIN: '[]', // e.g., kmaida.auth0.com
AUDIENCE: '[http://localhost:8083/api/]', // e.g., http://localhost:8083/api/
REDIRECT: `${ENV.BASE_URI}/callback`,
SCOPE: 'openid profile email',
NAMESPACE: 'http://myapp.com/roles'
};
请看一下教程,也许会分享我可能错过的内容。
auth.service.ts 就这样使用配置文件
// Remove data from localStorage
this._clearExpiration();
this._clearRedirect();
// End Auth0 authentication session
this._auth0.logout({
clientId: AUTH_CONFIG.CLIENT_ID,
returnTo: ENV.BASE_URI
});
}
这就是我的 auth.service.ts
的导入部分的样子import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { BehaviorSubject, Subscription, of, timer } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
import { AUTH_CONFIG } from './auth.config';
import * as auth0 from 'auth0-js';
import { ENV } from './../core/env.config';
在我的 cmd 中发出的错误读取
src/app/auth/auth.service.ts:92:17 中的错误 - 错误 TS2304:找不到名称 >'ENV'。
92 返回到:ENV.BASE_URI。 我也怀疑从核心处理进口的方式有问题,因为我真的对斜线进口不太了解。 我有我的应用程序目录,其中包含 auth 和 core 文件夹作为直接子级。
【问题讨论】:
标签: javascript node.js angular auth0