From f86f727ac75bddb154e7b4fe9203909e1b8c73d9 Mon Sep 17 00:00:00 2001
From: Fuzi_fauzia 
Date: Tue, 9 Jul 2024 14:37:00 +0700
Subject: [PATCH] implement token exp
---
 src/app/_layout/footer/footer.component.html  |  2 +-
 .../cost-management.component.ts              |  3 +
 .../modal-add-actual.component.ts             |  5 +-
 .../modal-export/modal-export.component.ts    |  5 +-
 .../add-edit-device.component.ts              |  3 +
 .../device-control.component.ts               |  5 +-
 .../hemat-app/device/device.component.ts      |  5 +-
 .../add-edit-list/add-edit-list.component.ts  |  3 +
 .../list-monitoring.component.ts              |  5 +-
 .../add-edit-master.component.ts              |  5 +-
 .../add-edit-master-building.component.ts     |  5 +-
 .../master-building.component.ts              |  5 +-
 .../master-category.component.ts              |  5 +-
 .../master-duration-use.component.ts          |  5 +-
 .../master-floor/master-floor.component.ts    |  5 +-
 .../master-role/master-role.component.ts      |  5 +-
 .../add-edit-master-room.component.ts         |  5 +-
 .../master-room/master-room.component.ts      |  5 +-
 .../master-status/master-status.component.ts  |  5 +-
 .../master-type/master-type.component.ts      |  5 +-
 .../master-voltage.component.ts               |  5 +-
 .../monitoring/building/building.component.ts |  5 +-
 .../control-device-seemore.component.ts       |  3 +
 .../monitoring/detail/detail.component.ts     |  3 +
 .../monitoring/room/room.component.ts         |  3 +
 .../hemat-app/service/login.service.ts        | 56 +++++++++++++++++--
 .../profil-information.component.ts           |  8 ++-
 .../update-password.component.ts              |  1 +
 src/app/login/login.component.html            |  2 +-
 29 files changed, 152 insertions(+), 25 deletions(-)
diff --git a/src/app/_layout/footer/footer.component.html b/src/app/_layout/footer/footer.component.html
index ae7c7dc..cdfa2a6 100644
--- a/src/app/_layout/footer/footer.component.html
+++ b/src/app/_layout/footer/footer.component.html
@@ -13,7 +13,7 @@
         href="https://allbestsistem.com/"
         target="_blank"
         style="background-color: #000000 !important;"
-        >Smart Building Management Systems (V@2024-07-9.01)
+        >Smart Building Management Systems (V@2024-07-9.02)
       
   
diff --git a/src/app/content/hemat-app/cost-management/cost-management.component.ts b/src/app/content/hemat-app/cost-management/cost-management.component.ts
index 52acf37..9b7b3b9 100644
--- a/src/app/content/hemat-app/cost-management/cost-management.component.ts
+++ b/src/app/content/hemat-app/cost-management/cost-management.component.ts
@@ -7,6 +7,7 @@ import "chartist-plugin-tooltips";
 import { ModalExportComponent } from "./modal-export/modal-export.component";
 import { TableexcelService } from "src/app/_services/tableexcel.service";
 import { ToastrService } from "ngx-toastr";
+import { LoginService } from "../service/login.service";
 
 @Component({
   selector: "app-cost-management",
@@ -49,9 +50,11 @@ export class CostManagementComponent implements OnInit {
     private modalService: NgbModal,
     private tableexcelService: TableexcelService,
     private toastr: ToastrService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Cost Management",
       links: [
diff --git a/src/app/content/hemat-app/cost-management/modal-add-actual/modal-add-actual.component.ts b/src/app/content/hemat-app/cost-management/modal-add-actual/modal-add-actual.component.ts
index f2f0b3a..94a5360 100644
--- a/src/app/content/hemat-app/cost-management/modal-add-actual/modal-add-actual.component.ts
+++ b/src/app/content/hemat-app/cost-management/modal-add-actual/modal-add-actual.component.ts
@@ -2,6 +2,7 @@ import { Component, Input } from "@angular/core";
 import { FormBuilder, FormGroup, Validators } from "@angular/forms";
 import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
 import { CostManagementService } from "../../service/cost-management.service";
+import { LoginService } from "../../service/login.service";
 
 @Component({
   selector: "app-modal-add-actual",
@@ -22,12 +23,14 @@ export class ModalAddActualComponent {
   constructor(
     public activeModal: NgbActiveModal,
     private fb: FormBuilder,
-    private costService: CostManagementService
+    private costService: CostManagementService,
+    private authService: LoginService
   ) {
     this.createForm();
   }
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     const currentDate = new Date();
     this.dateCurrent = currentDate.toISOString().slice(0, 7);
     this.dateFormat();
diff --git a/src/app/content/hemat-app/cost-management/modal-export/modal-export.component.ts b/src/app/content/hemat-app/cost-management/modal-export/modal-export.component.ts
index b0463ba..27ad24d 100644
--- a/src/app/content/hemat-app/cost-management/modal-export/modal-export.component.ts
+++ b/src/app/content/hemat-app/cost-management/modal-export/modal-export.component.ts
@@ -3,6 +3,7 @@ import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
 import { DeviceService } from "../../service/device.service";
 import { CostManagementService } from "../../service/cost-management.service";
 import { TableexcelService } from "src/app/_services/tableexcel.service";
+import { LoginService } from "../../service/login.service";
 
 @Component({
   selector: "app-modal-export",
@@ -24,10 +25,12 @@ export class ModalExportComponent {
   constructor(
     public activeModal: NgbActiveModal,
     private costService: CostManagementService,
-    private tableexcelService: TableexcelService
+    private tableexcelService: TableexcelService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     const dateRow = this.convertToUTC7(this.dataRow.endDate)
     this.formattedEndDate = dateRow.slice(0, 7);
   }
diff --git a/src/app/content/hemat-app/device/add-edit-device/add-edit-device.component.ts b/src/app/content/hemat-app/device/add-edit-device/add-edit-device.component.ts
index 47af959..4e47f73 100644
--- a/src/app/content/hemat-app/device/add-edit-device/add-edit-device.component.ts
+++ b/src/app/content/hemat-app/device/add-edit-device/add-edit-device.component.ts
@@ -3,6 +3,7 @@ import { FormBuilder, FormGroup, NgForm, Validators } from "@angular/forms";
 import { ActivatedRoute, Router } from "@angular/router";
 import { BlockUI, NgBlockUI } from "ng-block-ui";
 import { BuildingService } from "../../service/monitoring-api.service";
+import { LoginService } from "../../service/login.service";
 
 @Component({
   selector: "app-add-edit-device",
@@ -36,9 +37,11 @@ export class AddEditDeviceComponent implements OnInit{
     private router: Router,
     private route: ActivatedRoute,
     private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.route.params.subscribe(params => {
       const id = params['id'];
       this.deviceId = id;
diff --git a/src/app/content/hemat-app/device/device-control/device-control.component.ts b/src/app/content/hemat-app/device/device-control/device-control.component.ts
index b764daa..988eed4 100644
--- a/src/app/content/hemat-app/device/device-control/device-control.component.ts
+++ b/src/app/content/hemat-app/device/device-control/device-control.component.ts
@@ -3,6 +3,7 @@ import { Router } from "@angular/router";
 import { BuildingService } from "../../service/monitoring-api.service";
 import { DeviceService } from "../../service/device.service";
 import { ToastrService } from "ngx-toastr";
+import { LoginService } from "../../service/login.service";
 
 @Component({
   selector: "app-device-control",
@@ -32,10 +33,12 @@ export class DeviceControlComponent {
     private router: Router,
     private deviceService: DeviceService,
     private monitoringApiService: BuildingService,
-    private toastr: ToastrService
+    private toastr: ToastrService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Device",
       links: [
diff --git a/src/app/content/hemat-app/device/device.component.ts b/src/app/content/hemat-app/device/device.component.ts
index 297f627..7e830d1 100644
--- a/src/app/content/hemat-app/device/device.component.ts
+++ b/src/app/content/hemat-app/device/device.component.ts
@@ -9,6 +9,7 @@ import { ToastrService } from "ngx-toastr";
 import * as FileSaver from "file-saver";
 import * as XLSX from "xlsx";
 import { TableexcelService } from "src/app/_services/tableexcel.service";
+import { LoginService } from "../service/login.service";
 
 @Component({
   selector: "app-device",
@@ -47,10 +48,12 @@ export class DeviceComponent implements OnInit {
     private monitoringApiService: BuildingService,
     private deviceService: DeviceService,
     private toastr: ToastrService,
-    private tableexcelService: TableexcelService
+    private tableexcelService: TableexcelService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Device",
       links: [
diff --git a/src/app/content/hemat-app/list-monitoring/add-edit-list/add-edit-list.component.ts b/src/app/content/hemat-app/list-monitoring/add-edit-list/add-edit-list.component.ts
index 38e7f62..e47d324 100644
--- a/src/app/content/hemat-app/list-monitoring/add-edit-list/add-edit-list.component.ts
+++ b/src/app/content/hemat-app/list-monitoring/add-edit-list/add-edit-list.component.ts
@@ -3,6 +3,7 @@ import { FormArray, FormBuilder, FormGroup, NgForm, Validators } from '@angular/
 import { ActivatedRoute, Router } from '@angular/router';
 import { BlockUI, NgBlockUI } from 'ng-block-ui';
 import { BuildingService } from '../../service/monitoring-api.service';
+import { LoginService } from '../../service/login.service';
 
 @Component({
   selector: 'app-add-edit-list',
@@ -36,9 +37,11 @@ export class AddEditListComponent {
     private router: Router,
     private route: ActivatedRoute,
     private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.route.data.subscribe((data) => {
       this.mode = data.mode;
     });
diff --git a/src/app/content/hemat-app/list-monitoring/list-monitoring.component.ts b/src/app/content/hemat-app/list-monitoring/list-monitoring.component.ts
index a968ef4..22fc841 100644
--- a/src/app/content/hemat-app/list-monitoring/list-monitoring.component.ts
+++ b/src/app/content/hemat-app/list-monitoring/list-monitoring.component.ts
@@ -3,6 +3,7 @@ import { Router } from "@angular/router";
 import { TableApiService } from "src/app/_services/table-api.service";
 import { BuildingService } from "../service/monitoring-api.service";
 import Swal from "sweetalert2";
+import { LoginService } from "../service/login.service";
 
 @Component({
   selector: "app-list-monitoring",
@@ -19,10 +20,12 @@ export class ListMonitoringComponent {
   constructor(
     private tableApiservice: TableApiService,
     private router: Router,
-    private monitoringApiService: BuildingService
+    private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Cost Management",
       links: [
diff --git a/src/app/content/hemat-app/master/add-edit-master/add-edit-master.component.ts b/src/app/content/hemat-app/master/add-edit-master/add-edit-master.component.ts
index 9782328..a1ec93d 100644
--- a/src/app/content/hemat-app/master/add-edit-master/add-edit-master.component.ts
+++ b/src/app/content/hemat-app/master/add-edit-master/add-edit-master.component.ts
@@ -2,6 +2,7 @@ import { Component, Input, OnInit } from "@angular/core";
 import { FormBuilder, FormGroup, Validators } from "@angular/forms";
 import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
 import { BuildingService } from "../../service/monitoring-api.service";
+import { LoginService } from "../../service/login.service";
 
 @Component({
   selector: "app-add-edit-master",
@@ -21,10 +22,12 @@ export class AddEditMasterComponent implements OnInit {
   constructor(
     public activeModal: NgbActiveModal,
     private fb: FormBuilder,
-    private monitoringApiService: BuildingService
+    private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.createForm();
     this.dataListMaster();
     if (this.mode === "add") {
diff --git a/src/app/content/hemat-app/master/master-building/add-edit-master-building/add-edit-master-building.component.ts b/src/app/content/hemat-app/master/master-building/add-edit-master-building/add-edit-master-building.component.ts
index 932352d..36e11a5 100644
--- a/src/app/content/hemat-app/master/master-building/add-edit-master-building/add-edit-master-building.component.ts
+++ b/src/app/content/hemat-app/master/master-building/add-edit-master-building/add-edit-master-building.component.ts
@@ -2,6 +2,7 @@ import { Component, Input } from "@angular/core";
 import { FormBuilder, FormGroup, Validators } from "@angular/forms";
 import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
 import { BuildingService } from "../../../service/monitoring-api.service";
+import { LoginService } from "../../../service/login.service";
 
 @Component({
   selector: "app-add-edit-master-building",
@@ -21,10 +22,12 @@ export class AddEditMasterBuildingComponent {
   constructor(
     public activeModal: NgbActiveModal,
     private fb: FormBuilder,
-    private monitoringApiService: BuildingService
+    private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.createForm();
     this.listDataStatus();
 
diff --git a/src/app/content/hemat-app/master/master-building/master-building.component.ts b/src/app/content/hemat-app/master/master-building/master-building.component.ts
index 25de63a..1c00431 100644
--- a/src/app/content/hemat-app/master/master-building/master-building.component.ts
+++ b/src/app/content/hemat-app/master/master-building/master-building.component.ts
@@ -5,6 +5,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
 import { Router } from '@angular/router';
 import { BuildingService } from '../../service/monitoring-api.service';
 import { AddEditMasterBuildingComponent } from './add-edit-master-building/add-edit-master-building.component';
+import { LoginService } from '../../service/login.service';
 
 @Component({
   selector: 'app-master-building',
@@ -22,10 +23,12 @@ export class MasterBuildingComponent {
     private tableApiservice: TableApiService,
     private modalService: NgbModal,
     private router: Router,
-    private monitoringApiService: BuildingService
+    private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Master Building",
       links: [
diff --git a/src/app/content/hemat-app/master/master-category/master-category.component.ts b/src/app/content/hemat-app/master/master-category/master-category.component.ts
index a9adb3f..b73b22b 100644
--- a/src/app/content/hemat-app/master/master-category/master-category.component.ts
+++ b/src/app/content/hemat-app/master/master-category/master-category.component.ts
@@ -6,6 +6,7 @@ import { TableApiService } from "src/app/_services/table-api.service";
 import { BuildingService } from "../../service/monitoring-api.service";
 import { AddEditMasterComponent } from "../add-edit-master/add-edit-master.component";
 import { ToastrService } from "ngx-toastr";
+import { LoginService } from "../../service/login.service";
 
 @Component({
   selector: "app-master-category",
@@ -27,10 +28,12 @@ export class MasterCategoryComponent implements OnInit {
     private modalService: NgbModal,
     private router: Router,
     private monitoringApiService: BuildingService,
-    private toastr: ToastrService
+    private toastr: ToastrService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Master Category",
       links: [
diff --git a/src/app/content/hemat-app/master/master-duration-use/master-duration-use.component.ts b/src/app/content/hemat-app/master/master-duration-use/master-duration-use.component.ts
index c0432c9..f18cc20 100644
--- a/src/app/content/hemat-app/master/master-duration-use/master-duration-use.component.ts
+++ b/src/app/content/hemat-app/master/master-duration-use/master-duration-use.component.ts
@@ -4,6 +4,7 @@ import { TableApiService } from 'src/app/_services/table-api.service';
 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
 import { Router } from '@angular/router';
 import { BuildingService } from '../../service/monitoring-api.service';
+import { LoginService } from '../../service/login.service';
 
 @Component({
   selector: 'app-master-duration-use',
@@ -22,10 +23,12 @@ export class MasterDurationUseComponent {
     private tableApiservice: TableApiService,
     private modalService: NgbModal,
     private router: Router,
-    private monitoringApiService: BuildingService
+    private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Master Duration Use",
       links: [
diff --git a/src/app/content/hemat-app/master/master-floor/master-floor.component.ts b/src/app/content/hemat-app/master/master-floor/master-floor.component.ts
index c3cdfc5..fd68abf 100644
--- a/src/app/content/hemat-app/master/master-floor/master-floor.component.ts
+++ b/src/app/content/hemat-app/master/master-floor/master-floor.component.ts
@@ -4,6 +4,7 @@ import { TableApiService } from 'src/app/_services/table-api.service';
 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
 import { Router } from '@angular/router';
 import { BuildingService } from '../../service/monitoring-api.service';
+import { LoginService } from '../../service/login.service';
 
 @Component({
   selector: 'app-master-floor',
@@ -22,10 +23,12 @@ export class MasterFloorComponent {
     private tableApiservice: TableApiService,
     private modalService: NgbModal,
     private router: Router,
-    private monitoringApiService: BuildingService
+    private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Master Floor",
       links: [
diff --git a/src/app/content/hemat-app/master/master-role/master-role.component.ts b/src/app/content/hemat-app/master/master-role/master-role.component.ts
index 85aa99b..75a2c6e 100644
--- a/src/app/content/hemat-app/master/master-role/master-role.component.ts
+++ b/src/app/content/hemat-app/master/master-role/master-role.component.ts
@@ -4,6 +4,7 @@ import { TableApiService } from 'src/app/_services/table-api.service';
 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
 import { Router } from '@angular/router';
 import { BuildingService } from '../../service/monitoring-api.service';
+import { LoginService } from '../../service/login.service';
 
 @Component({
   selector: 'app-master-role',
@@ -22,10 +23,12 @@ export class MasterRoleComponent {
     private tableApiservice: TableApiService,
     private modalService: NgbModal,
     private router: Router,
-    private monitoringApiService: BuildingService
+    private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Master Role",
       links: [
diff --git a/src/app/content/hemat-app/master/master-room/add-edit-master-room/add-edit-master-room.component.ts b/src/app/content/hemat-app/master/master-room/add-edit-master-room/add-edit-master-room.component.ts
index d90cb84..1cdb739 100644
--- a/src/app/content/hemat-app/master/master-room/add-edit-master-room/add-edit-master-room.component.ts
+++ b/src/app/content/hemat-app/master/master-room/add-edit-master-room/add-edit-master-room.component.ts
@@ -2,6 +2,7 @@ import { Component, Input } from "@angular/core";
 import { FormBuilder, FormGroup, Validators } from "@angular/forms";
 import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
 import { BuildingService } from "../../../service/monitoring-api.service";
+import { LoginService } from "../../../service/login.service";
 
 @Component({
   selector: "app-add-edit-master-room",
@@ -24,10 +25,12 @@ export class AddEditMasterRoomComponent {
   constructor(
     public activeModal: NgbActiveModal,
     private fb: FormBuilder,
-    private monitoringApiService: BuildingService
+    private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.createForm();
     this.listDataStatus();
     this.listDataBuilding();
diff --git a/src/app/content/hemat-app/master/master-room/master-room.component.ts b/src/app/content/hemat-app/master/master-room/master-room.component.ts
index 02f9e5f..a6e3ef6 100644
--- a/src/app/content/hemat-app/master/master-room/master-room.component.ts
+++ b/src/app/content/hemat-app/master/master-room/master-room.component.ts
@@ -4,6 +4,7 @@ import { TableApiService } from "src/app/_services/table-api.service";
 import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
 import { Router } from "@angular/router";
 import { BuildingService } from "../../service/monitoring-api.service";
+import { LoginService } from "../../service/login.service";
 
 @Component({
   selector: "app-master-room",
@@ -19,10 +20,12 @@ export class MasterRoomComponent {
 
   constructor(
     private modalService: NgbModal,
-    private monitoringApiService: BuildingService
+    private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Master Room",
       links: [
diff --git a/src/app/content/hemat-app/master/master-status/master-status.component.ts b/src/app/content/hemat-app/master/master-status/master-status.component.ts
index 54a0017..6ddb73c 100644
--- a/src/app/content/hemat-app/master/master-status/master-status.component.ts
+++ b/src/app/content/hemat-app/master/master-status/master-status.component.ts
@@ -4,6 +4,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
 import { TableApiService } from 'src/app/_services/table-api.service';
 import { BuildingService } from '../../service/monitoring-api.service';
 import { AddEditMasterComponent } from '../add-edit-master/add-edit-master.component';
+import { LoginService } from '../../service/login.service';
 
 @Component({
   selector: 'app-master-status',
@@ -22,10 +23,12 @@ export class MasterStatusComponent {
     private tableApiservice: TableApiService,
     private modalService: NgbModal,
     private router: Router,
-    private monitoringApiService: BuildingService
+    private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Master Status",
       links: [
diff --git a/src/app/content/hemat-app/master/master-type/master-type.component.ts b/src/app/content/hemat-app/master/master-type/master-type.component.ts
index a6bed8a..8af4853 100644
--- a/src/app/content/hemat-app/master/master-type/master-type.component.ts
+++ b/src/app/content/hemat-app/master/master-type/master-type.component.ts
@@ -4,6 +4,7 @@ import { TableApiService } from 'src/app/_services/table-api.service';
 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
 import { Router } from '@angular/router';
 import { BuildingService } from '../../service/monitoring-api.service';
+import { LoginService } from '../../service/login.service';
 
 @Component({
   selector: 'app-master-type',
@@ -22,10 +23,12 @@ export class MasterTypeComponent {
     private tableApiservice: TableApiService,
     private modalService: NgbModal,
     private router: Router,
-    private monitoringApiService: BuildingService
+    private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Master Type",
       links: [
diff --git a/src/app/content/hemat-app/master/master-voltage/master-voltage.component.ts b/src/app/content/hemat-app/master/master-voltage/master-voltage.component.ts
index 0449979..638183f 100644
--- a/src/app/content/hemat-app/master/master-voltage/master-voltage.component.ts
+++ b/src/app/content/hemat-app/master/master-voltage/master-voltage.component.ts
@@ -4,6 +4,7 @@ import { TableApiService } from 'src/app/_services/table-api.service';
 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
 import { Router } from '@angular/router';
 import { BuildingService } from '../../service/monitoring-api.service';
+import { LoginService } from '../../service/login.service';
 
 @Component({
   selector: 'app-master-voltage',
@@ -22,10 +23,12 @@ export class MasterVoltageComponent {
     private tableApiservice: TableApiService,
     private modalService: NgbModal,
     private router: Router,
-    private monitoringApiService: BuildingService
+    private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Master Voltage",
       links: [
diff --git a/src/app/content/hemat-app/monitoring/building/building.component.ts b/src/app/content/hemat-app/monitoring/building/building.component.ts
index c0a515c..bb5340f 100644
--- a/src/app/content/hemat-app/monitoring/building/building.component.ts
+++ b/src/app/content/hemat-app/monitoring/building/building.component.ts
@@ -2,6 +2,7 @@ import { Component } from "@angular/core";
 import { TableMonitoringService } from "../monitoring.service";
 import { Router } from "@angular/router";
 import { BuildingService } from "../../service/monitoring-api.service";
+import { LoginService } from "../../service/login.service";
 
 @Component({
   selector: "app-building",
@@ -21,10 +22,12 @@ export class BuildingComponent {
   constructor(
     private monitoringService: TableMonitoringService,
     private monitoringApiService: BuildingService,
-    private router: Router
+    private router: Router,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.breadcrumb = {
       mainlabel: "Dashboard",
       links: [
diff --git a/src/app/content/hemat-app/monitoring/control-device-seemore/control-device-seemore.component.ts b/src/app/content/hemat-app/monitoring/control-device-seemore/control-device-seemore.component.ts
index 97d71b2..ae0e115 100644
--- a/src/app/content/hemat-app/monitoring/control-device-seemore/control-device-seemore.component.ts
+++ b/src/app/content/hemat-app/monitoring/control-device-seemore/control-device-seemore.component.ts
@@ -3,6 +3,7 @@ import { BuildingService } from '../../service/monitoring-api.service';
 import { DeviceService } from '../../service/device.service';
 import { ActivatedRoute, Router } from '@angular/router';
 import { ToastrService } from 'ngx-toastr';
+import { LoginService } from '../../service/login.service';
 
 @Component({
   selector: 'app-control-device-seemore',
@@ -32,9 +33,11 @@ export class ControlDeviceSeemoreComponent {
     private monitoringApiService: BuildingService,
     private route: ActivatedRoute,
     private toastr: ToastrService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.route.params.subscribe((params) => {
       const buildingId = params["id"];
       this.paramsId = buildingId ? buildingId: 0;
diff --git a/src/app/content/hemat-app/monitoring/detail/detail.component.ts b/src/app/content/hemat-app/monitoring/detail/detail.component.ts
index a19e4f1..86f698d 100644
--- a/src/app/content/hemat-app/monitoring/detail/detail.component.ts
+++ b/src/app/content/hemat-app/monitoring/detail/detail.component.ts
@@ -3,6 +3,7 @@ import { ActivatedRoute, Router } from "@angular/router";
 import { ChartOptions, ChartType, ChartDataset } from "chart.js";
 import { EnergyMonitoringService } from "../../service/energy-monitoring.service";
 import { CurrencyPipe } from "@angular/common";
+import { LoginService } from "../../service/login.service";
 
 @Component({
   selector: "app-detail",
@@ -126,6 +127,7 @@ export class DetailComponent {
     private energyMonitoringService: EnergyMonitoringService,
     private currencyPipe: CurrencyPipe,
     private router: Router,
+    private authService: LoginService
   ) {}
 
   get formattedSummaryCost(): string {
@@ -138,6 +140,7 @@ export class DetailComponent {
   }
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.route.data.subscribe((data) => {
       this.mode = data.mode;
     });
diff --git a/src/app/content/hemat-app/monitoring/room/room.component.ts b/src/app/content/hemat-app/monitoring/room/room.component.ts
index fd2b209..4eb4f62 100644
--- a/src/app/content/hemat-app/monitoring/room/room.component.ts
+++ b/src/app/content/hemat-app/monitoring/room/room.component.ts
@@ -2,6 +2,7 @@ import { Component, OnInit } from "@angular/core";
 import { ActivatedRoute, Router } from "@angular/router";
 import { TableMonitoringService } from "../monitoring.service";
 import { BuildingService } from "../../service/monitoring-api.service";
+import { LoginService } from "../../service/login.service";
 
 @Component({
   selector: "app-room",
@@ -20,9 +21,11 @@ export class RoomComponent implements OnInit {
     private monitoringService: TableMonitoringService,
     private router: Router,
     private monitoringApiService: BuildingService,
+    private authService: LoginService
   ) {}
 
   ngOnInit() {
+    this.authService.checkTokenAndRedirect();
     this.route.data.subscribe((data) => {
       this.mode = data.mode;
       console.log(this.mode);
diff --git a/src/app/content/hemat-app/service/login.service.ts b/src/app/content/hemat-app/service/login.service.ts
index 1e01c0a..a34d019 100644
--- a/src/app/content/hemat-app/service/login.service.ts
+++ b/src/app/content/hemat-app/service/login.service.ts
@@ -1,21 +1,40 @@
 import { Injectable } from "@angular/core";
 import { HttpClient, HttpHeaders } from "@angular/common/http";
 import { Observable } from "rxjs";
+import { jwtDecode } from "jwt-decode";
+import { Router } from "@angular/router";
+import { AuthService } from "src/app/_services/auth.service";
 
-const BASE_URL = 'https://kapi.absys.ninja/hemat';
+const BASE_URL = "https://kapi.absys.ninja/hemat";
+interface CustomJwtPayload {
+  exp: number;
+  scope: string;
+  iat: number;
+  preferred_username: string;
+  name: string;
+  email: string;
+  family_name: string;
+  given_name: string;
+  sub: string;
+}
 
 @Injectable({
   providedIn: "root",
 })
 export class LoginService {
-  constructor(private http: HttpClient) {}
+  private readonly tokenKey = "currentUser";
+  constructor(
+    private http: HttpClient,
+    private router: Router,
+    public logoutService: AuthService
+  ) {}
 
   updatePassword(data: any): Observable {
     const endpoint = `/users`;
     const url = `${BASE_URL}${endpoint}/reset-password`;
     const headers = new HttpHeaders({
-      'Content-Type': 'application/json',
-      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
+      "Content-Type": "application/json",
+      "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT",
     });
     return this.http.put(url, data, { headers });
   }
@@ -51,4 +70,33 @@ export class LoginService {
     return this.http.post(`${url}`, body, { headers });
   }
 
+  isTokenExpired(): boolean {
+    const tokenData = localStorage.getItem(this.tokenKey);
+    if (tokenData) {
+      const tokenInfo = JSON.parse(tokenData);
+      const decodedToken = jwtDecode(tokenInfo.refresh_token);
+      const expiryDate = decodedToken.exp * 1000;
+      const now = new Date().getTime();
+      return now > expiryDate;
+    }
+    return true;
+  }
+
+  checkTokenAndRedirect(): void {
+    if (this.isTokenExpired()) {
+      // Token sudah kedaluwarsa, arahkan ke halaman login
+      // console.log("Token expired, redirecting to login page...");
+      this.logoutService.doLogout().then(
+        (res) => {
+          this.router.navigate(["/login"]);
+        },
+        (err) => {
+          console.log(err);
+        }
+      );
+      this.router.navigate(["/login"]);
+    } else {
+      console.log("Token is valid, continuing...");
+    }
+  }
 }
diff --git a/src/app/content/hemat-app/user-profile/profil-information/profil-information.component.ts b/src/app/content/hemat-app/user-profile/profil-information/profil-information.component.ts
index e1eb5de..98e5316 100644
--- a/src/app/content/hemat-app/user-profile/profil-information/profil-information.component.ts
+++ b/src/app/content/hemat-app/user-profile/profil-information/profil-information.component.ts
@@ -3,6 +3,8 @@ import { FormBuilder, FormGroup, NgForm, Validators } from "@angular/forms";
 import { LoginService } from "../../service/login.service";
 import { ToastrService } from "ngx-toastr";
 import { jwtDecode } from "jwt-decode";
+import { AuthService } from "src/app/_services/auth.service";
+import { Router } from "@angular/router";
 interface CustomJwtPayload {
   exp: number;
   scope: string;
@@ -35,12 +37,16 @@ export class ProfilInformationComponent {
   constructor(
     private formBuilder: FormBuilder,
     private authService: LoginService,
-    private toastr: ToastrService
+    private toastr: ToastrService,
+    public logoutService: AuthService,
+    private router: Router
   ) {}
 
   ngOnInit(): void {
     this.storedData = JSON.parse(localStorage.getItem("account_info"));
     this.currentUser = JSON.parse(localStorage.getItem("currentUser"));
+    this.authService.checkTokenAndRedirect();
+
     this.profilInfo = this.formBuilder.group({
       firstName: ["", Validators.required],
       lastName: ["", Validators.required],
diff --git a/src/app/content/hemat-app/user-profile/update-password/update-password.component.ts b/src/app/content/hemat-app/user-profile/update-password/update-password.component.ts
index ccb99de..3137230 100644
--- a/src/app/content/hemat-app/user-profile/update-password/update-password.component.ts
+++ b/src/app/content/hemat-app/user-profile/update-password/update-password.component.ts
@@ -40,6 +40,7 @@ export class UpdatePasswordComponent {
 
   ngOnInit(): void {
     this.storedData = JSON.parse(localStorage.getItem("account_info"));
+    this.authService.checkTokenAndRedirect();
     this.profilInfo = this.formBuilder.group({
       userid: this.storedData.sub,
       currentPass: [""],
diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html
index a351d69..b1f0676 100644
--- a/src/app/login/login.component.html
+++ b/src/app/login/login.component.html
@@ -138,7 +138,7 @@
                 
-                  (v@2024.07.9.01)
+                  (v@2024.07.9.02)