* Schedule token refresh before expiration
()
| 151 | * Schedule token refresh before expiration |
| 152 | */ |
| 153 | private scheduleRefresh(): void { |
| 154 | if (this.refreshTimer) { |
| 155 | clearTimeout(this.refreshTimer) |
| 156 | } |
| 157 | |
| 158 | const authData = this.store.load() |
| 159 | if (!authData) return |
| 160 | |
| 161 | const expiresAt = new Date(authData.expiresAt).getTime() |
| 162 | const now = Date.now() |
| 163 | |
| 164 | // Refresh 5 minutes before expiration |
| 165 | const refreshIn = Math.max(0, expiresAt - now - 5 * 60 * 1000) |
| 166 | |
| 167 | this.refreshTimer = setTimeout(() => { |
| 168 | this.refresh() |
| 169 | }, refreshIn) |
| 170 | |
| 171 | console.log(`Scheduled token refresh in ${Math.round(refreshIn / 1000 / 60)} minutes`) |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Check if user is authenticated |
no test coverage detected