added session logout timer
This commit is contained in:
parent
8c314bff50
commit
524989905c
3 changed files with 20 additions and 4 deletions
|
|
@ -44,6 +44,7 @@ export class AppComponent {
|
|||
private route: ActivatedRoute,
|
||||
private router: Router
|
||||
) {
|
||||
this.checkAndClearLocalStorage();
|
||||
this.isLoggedIn = this.firebaseService.getCurrentUserId();
|
||||
}
|
||||
|
||||
|
|
@ -56,6 +57,19 @@ export class AppComponent {
|
|||
}
|
||||
}
|
||||
|
||||
checkAndClearLocalStorage() {
|
||||
const startTime = localStorage.getItem('sessionTimeJOIN');
|
||||
|
||||
if (startTime) {
|
||||
const startTimeMillis = parseInt(startTime);
|
||||
const currentTime = new Date().getTime();
|
||||
const timeDifference = 12 * 60 * 60 * 1000; // 12h
|
||||
if (currentTime - startTimeMillis > timeDifference) {
|
||||
localStorage.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkPwResetRoute() {
|
||||
this.router.events
|
||||
.pipe(filter((event) => event instanceof NavigationEnd))
|
||||
|
|
|
|||
|
|
@ -121,7 +121,8 @@
|
|||
}
|
||||
</div>
|
||||
<div class="btns">
|
||||
@if (currentUserId){
|
||||
@if (currentUserId && currentUserId !==
|
||||
firebaseService.getCurrentUserId()){
|
||||
<app-form-btn
|
||||
class="btn-delete"
|
||||
type="button"
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ export class LoginService {
|
|||
const user = userCredential.user;
|
||||
const userData = this.firebaseService.getUserDataFromUid(user.uid);
|
||||
if (userData.length > 0 && userData[0].id) {
|
||||
this.getUserIdInLocalStorage(this.secretKey, userData[0].id);
|
||||
this.getUserIdInLocalStorage(userData[0].id);
|
||||
this.updateUserOnlineStatus(userData[0].id, true);
|
||||
}
|
||||
})
|
||||
|
|
@ -161,7 +161,7 @@ export class LoginService {
|
|||
ifExistUser(user: string) {
|
||||
const userData = this.firebaseService.getUserDataFromUid(user);
|
||||
if (userData.length > 0 && userData[0].id) {
|
||||
this.getUserIdInLocalStorage(this.secretKey, userData[0].id);
|
||||
this.getUserIdInLocalStorage(userData[0].id);
|
||||
this.updateUserOnlineStatus(userData[0].id, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -187,12 +187,13 @@ export class LoginService {
|
|||
: './../../../assets/img/login/close-eye.svg';
|
||||
}
|
||||
|
||||
getUserIdInLocalStorage(key: string, userId: string): void {
|
||||
getUserIdInLocalStorage(userId: string): void {
|
||||
const encryptedValue = CryptoJS.AES.encrypt(
|
||||
JSON.stringify(userId),
|
||||
this.secretKey
|
||||
).toString();
|
||||
localStorage.setItem('currentUserJOIN', encryptedValue);
|
||||
localStorage.setItem('sessionTimeJOIN', new Date().getTime().toString());
|
||||
}
|
||||
|
||||
// LOGOUT
|
||||
|
|
|
|||
Loading…
Reference in a new issue