logout.component.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { Inject, Optional, Component, OnInit } from '@angular/core';
  17. import { ActivatedRoute, Router } from '@angular/router';
  18. import { ReuseTabService } from '@delon/abc/reuse-tab';
  19. import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
  20. import { SettingsService } from '@delon/theme';
  21. import { finalize } from 'rxjs/operators';
  22. import { AuthnService } from '../../service/authn.service';
  23. import { SocialsProviderService } from '../../service/socials-provider.service';
  24. import { CONSTS } from '../../shared/consts';
  25. @Component({
  26. selector: 'app-logout',
  27. template: ``
  28. })
  29. export class LogoutComponent implements OnInit {
  30. redirect_uri = '';
  31. constructor(
  32. private router: Router,
  33. private settingsService: SettingsService,
  34. private authnService: AuthnService,
  35. @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,
  36. @Optional()
  37. @Inject(ReuseTabService)
  38. private reuseTabService: ReuseTabService,
  39. private route: ActivatedRoute
  40. ) { }
  41. ngOnInit(): void {
  42. this.redirect_uri = this.route.snapshot.params[CONSTS.REDIRECT_URI];
  43. this.authnService
  44. .logout()
  45. .pipe(
  46. finalize(() => {
  47. this.tokenService.clear();
  48. if (this.redirect_uri == null || this.redirect_uri == '') {
  49. this.router.navigateByUrl(this.tokenService.login_url!);
  50. } else {
  51. this.router.navigateByUrl(this.redirect_uri);
  52. }
  53. })
  54. )
  55. .subscribe(res => {
  56. console.log(`Logout Response ${res.data}`);
  57. });
  58. }
  59. }