1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import { Component, Inject } from '@angular/core';
|
7 | import { Router } from '@angular/router';
|
8 | import { NB_AUTH_OPTIONS } from '../../auth.options';
|
9 | import { getDeepFromObject } from '../../helpers';
|
10 | import { NbAuthService } from '../../services/auth.service';
|
11 | export 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 | }
|
38 | NbLogoutComponent.decorators = [
|
39 | { type: Component, args: [{
|
40 | selector: 'nb-logout',
|
41 | template: "<div>Logging out, please wait...</div>\n"
|
42 | },] }
|
43 | ];
|
44 | NbLogoutComponent.ctorParameters = () => [
|
45 | { type: NbAuthService },
|
46 | { type: undefined, decorators: [{ type: Inject, args: [NB_AUTH_OPTIONS,] }] },
|
47 | { type: Router }
|
48 | ];
|
49 |
|
\ | No newline at end of file |