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 route: ActivatedRoute,
|
||||||
private router: Router
|
private router: Router
|
||||||
) {
|
) {
|
||||||
|
this.checkAndClearLocalStorage();
|
||||||
this.isLoggedIn = this.firebaseService.getCurrentUserId();
|
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() {
|
checkPwResetRoute() {
|
||||||
this.router.events
|
this.router.events
|
||||||
.pipe(filter((event) => event instanceof NavigationEnd))
|
.pipe(filter((event) => event instanceof NavigationEnd))
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,8 @@
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<div class="btns">
|
<div class="btns">
|
||||||
@if (currentUserId){
|
@if (currentUserId && currentUserId !==
|
||||||
|
firebaseService.getCurrentUserId()){
|
||||||
<app-form-btn
|
<app-form-btn
|
||||||
class="btn-delete"
|
class="btn-delete"
|
||||||
type="button"
|
type="button"
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ export class LoginService {
|
||||||
const user = userCredential.user;
|
const user = userCredential.user;
|
||||||
const userData = this.firebaseService.getUserDataFromUid(user.uid);
|
const userData = this.firebaseService.getUserDataFromUid(user.uid);
|
||||||
if (userData.length > 0 && userData[0].id) {
|
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);
|
this.updateUserOnlineStatus(userData[0].id, true);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -161,7 +161,7 @@ export class LoginService {
|
||||||
ifExistUser(user: string) {
|
ifExistUser(user: string) {
|
||||||
const userData = this.firebaseService.getUserDataFromUid(user);
|
const userData = this.firebaseService.getUserDataFromUid(user);
|
||||||
if (userData.length > 0 && userData[0].id) {
|
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);
|
this.updateUserOnlineStatus(userData[0].id, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -187,12 +187,13 @@ export class LoginService {
|
||||||
: './../../../assets/img/login/close-eye.svg';
|
: './../../../assets/img/login/close-eye.svg';
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserIdInLocalStorage(key: string, userId: string): void {
|
getUserIdInLocalStorage(userId: string): void {
|
||||||
const encryptedValue = CryptoJS.AES.encrypt(
|
const encryptedValue = CryptoJS.AES.encrypt(
|
||||||
JSON.stringify(userId),
|
JSON.stringify(userId),
|
||||||
this.secretKey
|
this.secretKey
|
||||||
).toString();
|
).toString();
|
||||||
localStorage.setItem('currentUserJOIN', encryptedValue);
|
localStorage.setItem('currentUserJOIN', encryptedValue);
|
||||||
|
localStorage.setItem('sessionTimeJOIN', new Date().getTime().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOGOUT
|
// LOGOUT
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue