각도 5의 SPA를 구축 중이며 인증 및 인증 서비스를 요청하고 있습니다. 이 서비스는 세션이 활성 상태인지 확인하고 세션이 없거나 만료 된 경우 401 및 회사 전체 로그인 페이지가있는 HTML을 반환합니다. I는 다음과 같이,이 호출을 만들기위한 서비스를 구축 : 당신이 볼 수 있듯이, 내가 서비스를 호출하고있어각도로 동적으로 생성 된 HTML 리디렉션
@Injectable()
export class AuthService {
private authServicePath = '/<path-to-the-service>';
private authToken: string;
private serviceURL: string;
private requestOptions: any;
constructor(private http: HttpClient, private cookieService: CookieService) { }
validateAuth() {
this.serviceURL = environment.endpoint + this.authServicePath;
this.authToken = this.cookieService.get('SESSION-TOKEN-COOKIE');
this.requestOptions = {
headers: new HttpHeaders(
{
'SESSION-TOKEN-COOKIE': this.authToken
}
)
};
return this
.http
.get(this.serviceURL, this.requestOptions)
.subscribe(
data => {
// Do nothing
},
(err: HttpErrorResponse) => {
/*window.document.write = err.error;
window.document.close();*/
}
);
}
}
. 토큰이 유효하면 아무 것도 할 수 없지만 활성/유효한 세션이없는 경우 서비스는 401 Unauthorized를 반환하고 페이로드 (.error
필드)에서 다음과 같이 표시합니다.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<form action="..." ...
내 생성 된 페이지로 리디렉션하도록 앱에 알리는 방법은 무엇입니까?
보시다시피, window.document.write
으로 새 HTML을 작성했지만 작동하지 않았습니다. 각도 라우터는 앱에 속한 구성 요소로만 리디렉션 할 수 있음을 알고 있습니다.
미리 감사드립니다.
전체 HTML 파일을 처리해야하기 때문에 더 나은 방법을 생각할 수 없습니다. 나는 당신의 예약에 동의합니다 - 그러나 그것은 작동합니다 ... – Steveland83