MCPcopy
hub / github.com/21st-dev/1code / scheduleRefresh

Method scheduleRefresh

src/main/auth-manager.ts:153–172  ·  view source on GitHub ↗

* Schedule token refresh before expiration

()

Source from the content-addressed store, hash-verified

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

Callers 3

constructorMethod · 0.95
exchangeCodeMethod · 0.95
refreshMethod · 0.95

Calls 2

refreshMethod · 0.95
loadMethod · 0.45

Tested by

no test coverage detected