Skip to content

Commit

Permalink
Add logout form
Browse files Browse the repository at this point in the history
  • Loading branch information
miladsoft committed Sep 14, 2024
1 parent 474184a commit 0ad2278
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions src/app/components/auth/logout/logout.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { I18nPluralPipe } from '@angular/common';
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { Router, RouterLink } from '@angular/router';
import { Subject, finalize, takeUntil, takeWhile, tap, timer } from 'rxjs';
import { SignerService } from 'app/services/signer.service';
import { Subject, finalize, takeUntil, takeWhile, tap, timer } from 'rxjs';

@Component({
selector: 'auth-logout',
Expand All @@ -18,42 +19,30 @@ export class LogoutComponent implements OnInit, OnDestroy {
};
private _unsubscribeAll: Subject<any> = new Subject<any>();

/**
* Constructor
*/
constructor(
private _router: Router
) {}
constructor(private _router: Router, private _signerService: SignerService) {}

// -----------------------------------------------------------------------------------------------------
// @ Lifecycle hooks
// -----------------------------------------------------------------------------------------------------

/**
* On init
*/
ngOnInit(): void {
// Logout

// Redirect after the countdown
timer(1000, 1000)
.pipe(
finalize(() => {
this._router.navigate(['login']);
}),
takeWhile(() => this.countdown > 0),
takeUntil(this._unsubscribeAll),
tap(() => this.countdown--)
tap(() => this.countdown--),
finalize(() => {
this.logout();
this._router.navigate(['login']);
})
)
.subscribe();
}

/**
* On destroy
*/

ngOnDestroy(): void {
// Unsubscribe from all subscriptions
this._unsubscribeAll.next(null);
this._unsubscribeAll.complete();
}

logout(): void {
this._signerService.logout();
console.log("User logged out and keys removed from localStorage.");
}
}

0 comments on commit 0ad2278

Please sign in to comment.