switchman-dev 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core/licence.js +14 -6
package/package.json
CHANGED
package/src/core/licence.js
CHANGED
|
@@ -123,6 +123,13 @@ export async function checkLicence() {
|
|
|
123
123
|
return { valid: false, reason: 'not_logged_in' };
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
// Proactively refresh if token expires within 5 minutes
|
|
127
|
+
if (creds.expires_at && Date.now() > creds.expires_at - 5 * 60 * 1000) {
|
|
128
|
+
if (creds.refresh_token) {
|
|
129
|
+
await refreshToken(creds.refresh_token);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
126
133
|
// Check the 24-hour cache first
|
|
127
134
|
const cache = readLicenceCache();
|
|
128
135
|
if (cache?.valid && cache.cached_at) {
|
|
@@ -134,12 +141,13 @@ export async function checkLicence() {
|
|
|
134
141
|
|
|
135
142
|
// Try live validation
|
|
136
143
|
try {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
144
|
+
const res = await fetch(VALIDATE_URL, {
|
|
145
|
+
headers: {
|
|
146
|
+
'Authorization': `Bearer ${SUPABASE_ANON}`,
|
|
147
|
+
'apikey': SUPABASE_ANON,
|
|
148
|
+
'x-user-token': creds.access_token,
|
|
149
|
+
},
|
|
150
|
+
});
|
|
143
151
|
|
|
144
152
|
if (!res.ok) {
|
|
145
153
|
// If token is expired, try to refresh
|