UNPKG

1.71 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright Akveo. All Rights Reserved.
4 * Licensed under the MIT License. See License.txt in the project root for license information.
5 */
6import { Component, Inject } from '@angular/core';
7import { Router } from '@angular/router';
8import { NB_AUTH_OPTIONS } from '../../auth.options';
9import { getDeepFromObject } from '../../helpers';
10import { NbAuthService } from '../../services/auth.service';
11export class NbLogoutComponent {
12 constructor(service, options = {}, router) {
13 this.service = service;
14 this.options = options;
15 this.router = router;
16 this.redirectDelay = 0;
17 this.strategy = '';
18 this.redirectDelay = this.getConfigValue('forms.logout.redirectDelay');
19 this.strategy = this.getConfigValue('forms.logout.strategy');
20 }
21 ngOnInit() {
22 this.logout(this.strategy);
23 }
24 logout(strategy) {
25 this.service.logout(strategy).subscribe((result) => {
26 const redirect = result.getRedirect();
27 if (redirect) {
28 setTimeout(() => {
29 return this.router.navigateByUrl(redirect);
30 }, this.redirectDelay);
31 }
32 });
33 }
34 getConfigValue(key) {
35 return getDeepFromObject(this.options, key, null);
36 }
37}
38NbLogoutComponent.decorators = [
39 { type: Component, args: [{
40 selector: 'nb-logout',
41 template: "<div>Logging out, please wait...</div>\n"
42 },] }
43];
44NbLogoutComponent.ctorParameters = () => [
45 { type: NbAuthService },
46 { type: undefined, decorators: [{ type: Inject, args: [NB_AUTH_OPTIONS,] }] },
47 { type: Router }
48];
49//# sourceMappingURL=logout.component.js.map
\No newline at end of file