Skip to content

Commit

Permalink
fix: refreshing token if VPN connection was reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed Oct 7, 2024
1 parent 69ad494 commit 28a3d98
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/stores/controller/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface UnitInfo {
interface UnitVpnData {
bytes_rcvd: string
bytes_sent: string
connected_since: string
connected_since: number
real_address: string
virtual_address: string
}
Expand Down Expand Up @@ -170,7 +170,11 @@ export const useUnitsStore = defineStore('units', () => {
const tokenDecoded: any = jwtDecode(loginInfo.token)
const tokenExpirationMillis = tokenDecoded.exp * 1000

if (tokenExpirationMillis > Date.now()) {
const tokenCreationMillis = tokenDecoded.orig_iat * 1000
const unitConnectionTime =
(unitsStore.units.find((unit) => unit.id == unitId)?.vpn.connected_since ?? 0) * 1000
// if the unit connection is newer than the token creation, we need to refresh the token
if (tokenExpirationMillis > Date.now() && tokenCreationMillis > unitConnectionTime) {
// unit token is still valid
return loginInfo.token
} else {
Expand Down

0 comments on commit 28a3d98

Please sign in to comment.