2017-12-17 25 views
0

SEO를 사용하기 위해 각도 2+ 응용 프로그램의 서버 측 렌더링을 추가하려고했습니다.각도 범용으로 auth0 사용하는 방법

이제 auth0-js를 사용하기 때문에 문제가 발생합니다.

콘솔 출력은 다음

public handleAuthentication(): void { 
this.auth0.parseHash((err, authResult) => { 
    if (authResult && authResult.accessToken && authResult.idToken) { 
    window.location.hash = ''; 
    this.setSession(authResult); 
    this.router.navigate(['/']); 
    } else if (err) { 
    this.router.navigate(['/']); 
    console.log(err); 
    alert(`Error: ${err.error}. Check the console for further details.`); 
    } 
}); 

} UPDATE가

:

나는 보편적 인 각도 추가 내가 auth0 예에서 기본 코드를 사용

ERROR { TypeError: Cannot read property 'location' of undefined at WebAuth.parseHash (C:\Dev\frontend\node_modules\auth0-js\src\web-auth\index.js:138:53) at e.handleAuthentication (C:\Dev\frontend\dist\server.js:8:523298) at new e (C:\Dev\frontend\dist\server.js:8:161974) at createClass (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:12509:20) at createDirectiveInstance (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:12) at createViewNodes (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:13815:53) at createRootView (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:13704:5) at Object.createProdRootView [as createRootView] (C:\Dev\frontend\node_modules\@angular\core\ s\core.umd.js:14397:12) at ComponentFactory_.create (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:1 6) at ComponentFactoryBoundToModule.create (C:\Dev\frontend\node_modules\@angular\core\bundles\c d.js:4070:29) __zone_symbol__currentTask: ZoneTask { _zone: Zone { _properties: [Object], _parent: [Object], _name: 'angular', _zoneDelegate: [Object] }, runCount: 0, _zoneDelegates: null, _state: 'notScheduled', type: 'microTask', source: 'Promise.then', data: undefined, scheduleFn: undefined, cancelFn: null, callback: [Function], invoke: [Function] } } Unhandled Promise rejection: Cannot read property 'location' of undefined ; Zone: <root> ; Task: Promise.then ; Value: { TypeError: Cannot read property 'location' of undefined at WebAuth.parseHash (C:\Dev\frontend\node_modules\auth0-js\src\web-auth\index.js:138:53) at e.handleAuthentication (C:\Dev\frontend\dist\server.js:8:523298) at new e (C:\Dev\frontend\dist\server.js:8:161974) at createClass (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:12509:20) at createDirectiveInstance (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:12 354:37) at createViewNodes (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:13815:53) at createRootView (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:13704:5) at Object.createProdRootView [as createRootView] (C:\Dev\frontend\node_modules\@angular\core\ bundles\core.umd.js:14397:12) at ComponentFactory_.create (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:1 1299:46) at ComponentFactoryBoundToModule.create (C:\Dev\frontend\node_modules\@angular\core\bundles\c ore.umd.js:4070:29) __zone_symbol__currentTask: ZoneTask { _zone: Zone { _properties: {}, _parent: null, _name: '<root>', _zoneDelegate: [Object] }, runCount: 0, _zoneDelegates: null, _state: 'notScheduled', type: 'microTask', source: 'Promise.then', data: undefined, scheduleFn: undefined, cancelFn: null, callback: [Function], invoke: [Function] } } TypeError: Cannot read property 'location' of undefined at WebAuth.parseHash (C:\Dev\frontend\node_modules\auth0-js\src\web-auth\index.js:138:53) at e.handleAuthentication (C:\Dev\frontend\dist\server.js:8:523298) at new e (C:\Dev\frontend\dist\server.js:8:161974) at createClass (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:12509:20) at createDirectiveInstance (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:12 354:37) at createViewNodes (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:13815:53) at createRootView (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:13704:5) at Object.createProdRootView [as createRootView] (C:\Dev\frontend\node_modules\@angular\core\ bundles\core.umd.js:14397:12) at ComponentFactory_.create (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:1 1299:46) at ComponentFactoryBoundToModule.create (C:\Dev\frontend\node_modules\@angular\core\bundles\c ore.umd.js:4070:29) 

내 인증 서비스에 문제가있다. 4200 :

는 지금은 최대한 빨리 localhost를 열로 다음과 같은 새로운 오류가

ERROR { Error: Uncaught (in promise): Error 
at resolvePromise (C:\Dev\frontend\node_modules\zone.js\dist\zone-node.js:824:31) 
at resolvePromise (C:\Dev\frontend\node_modules\zone.js\dist\zone-node.js:795:17) 
at C:\Dev\frontend\node_modules\zone.js\dist\zone-node.js:873:17 
at ZoneDelegate.invokeTask (C:\Dev\frontend\node_modules\zone.js\dist\zone-node.js:425:31) 
at Object.onInvokeTask (C:\Dev\frontend\node_modules\@angular\core\bundles\core.umd.js:4783:33) 
at ZoneDelegate.invokeTask (C:\Dev\frontend\node_modules\zone.js\dist\zone-node.js:424:36) 
at Zone.runTask (C:\Dev\frontend\node_modules\zone.js\dist\zone-node.js:192:47) 
at drainMicroTaskQueue (C:\Dev\frontend\node_modules\zone.js\dist\zone-node.js:602:35) 
at ZoneTask.invokeTask (C:\Dev\frontend\node_modules\zone.js\dist\zone-node.js:503:21) 
at Server.ZoneTask.invoke (C:\Dev\frontend\node_modules\zone.js\dist\zone-node.js:488:48) rejection: { [Error] 
__zone_symbol__currentTask: 
    ZoneTask { 
    _zone: [Object], 
    runCount: 0, 
    _zoneDelegates: null, 
    _state: 'notScheduled', 
    type: 'microTask', 
    source: 'Promise.then', 
    data: undefined, 
    scheduleFn: undefined, 
    cancelFn: null, 
    callback: [Function], 
    invoke: [Function] } }, promise: ZoneAwarePromise { 
__zone_symbol__state: 0, 
__zone_symbol__value: { [Error] __zone_symbol__currentTask: [Object] } }, zone: Zone { 
_properties: { isAngularZone: true }, 
_parent: 
    Zone { 
    _properties: {}, 
    _parent: null, 
    _name: '<root>', 
    _zoneDelegate: [Object] }, 
_name: 'angular', 
_zoneDelegate: 
    ZoneDelegate { 
    _taskCounts: [Object], 
    zone: [Circular], 
    _parentDelegate: [Object], 
    _forkZS: null, 
    _forkDlgt: null, 
    _forkCurrZone: [Object], 
    _interceptZS: null, 
    _interceptDlgt: null, 
    _interceptCurrZone: [Object], 
    _invokeZS: [Object], 
    _invokeDlgt: [Object], 
    _invokeCurrZone: [Circular], 
    _handleErrorZS: [Object], 
    _handleErrorDlgt: [Object], 
    _handleErrorCurrZone: [Circular], 
    _scheduleTaskZS: [Object], 
    _scheduleTaskDlgt: [Object], 
    _scheduleTaskCurrZone: [Circular], 
    _invokeTaskZS: [Object], 
    _invokeTaskDlgt: [Object], 
    _invokeTaskCurrZone: [Circular], 
    _cancelTaskZS: [Object], 
    _cancelTaskDlgt: [Object], 
    _cancelTaskCurrZone: [Circular], 
    _hasTaskZS: [Object], 
    _hasTaskDlgt: [Object], 
    _hasTaskDlgtOwner: [Circular], 
    _hasTaskCurrZone: [Circular] } }, task: ZoneTask { 
_zone: 
    Zone { 
    _properties: [Object], 
    _parent: [Object], 
    _name: 'angular', 
    _zoneDelegate: [Object] }, 
runCount: 0, 
_zoneDelegates: null, 
_state: 'notScheduled', 
type: 'microTask', 
source: 'Promise.then', 
data: undefined, 
scheduleFn: undefined, 
cancelFn: null, 
callback: [Function], 
invoke: [Function] } } 

누군가는 어떻게이 문제를 해결하는 아이디어가 있습니까?

많은 감사

답변

1

서버 측에서는 창, 문서 및 기타 브라우저 개체가 정의되지 않습니다.

서버 측 또는 클라이언트 측 인 경우에만 실행되는 플랫폼 특정 코드를 추가 할 수 있습니다.

https://github.com/angular/universal#universal-gotchas

참고 : 나는 예제 코드를 참조하지 않은,하지만 난 해시를 resettign하는 OU가 "/"후 어쨌든

+0

그게 올바른 탐색 여기에 경우에 유용하다는 것을 모르겠어요. 나는 네가 한 것처럼 생각했다. 이미 universal-gotchas를 추가했지만 httpclient 요청을받지 못합니다. –