@snapcommit/cli 3.8.0 → 3.8.2

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.
Files changed (2) hide show
  1. package/dist/lib/auth.js +44 -1
  2. package/package.json +1 -1
package/dist/lib/auth.js CHANGED
@@ -19,6 +19,9 @@ const CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.snapcommit');
19
19
  const AUTH_FILE = path_1.default.join(CONFIG_DIR, 'auth.json');
20
20
  // API URL - defaults to production, can be overridden for development
21
21
  const API_BASE_URL = process.env.SNAPCOMMIT_API_URL || 'https://snapcommit.dev';
22
+ // Token validation cache
23
+ let lastValidationTime = 0;
24
+ const VALIDATION_INTERVAL = 60 * 60 * 1000; // 1 hour in milliseconds
22
25
  /**
23
26
  * Ensure config directory exists
24
27
  */
@@ -163,11 +166,51 @@ async function promptAuth() {
163
166
  * Ensure user is authenticated (prompt if not)
164
167
  */
165
168
  async function ensureAuth() {
169
+ // Check if we have a locally stored token
166
170
  if (isAuthenticated()) {
167
- return getAuthConfig();
171
+ const config = getAuthConfig();
172
+ if (config) {
173
+ const now = Date.now();
174
+ const timeSinceLastValidation = now - lastValidationTime;
175
+ // Only validate if more than 1 hour has passed since last validation
176
+ if (timeSinceLastValidation > VALIDATION_INTERVAL) {
177
+ // CRITICAL: Verify token with server every hour
178
+ try {
179
+ const result = await verifyToken(config.token);
180
+ if (result.valid) {
181
+ // Token is still valid!
182
+ lastValidationTime = now; // Update last validation time
183
+ return config;
184
+ }
185
+ else {
186
+ // Token is invalid (user deleted, subscription expired, etc.)
187
+ console.log(chalk_1.default.yellow('\n⚠️ Your authentication token is no longer valid.'));
188
+ console.log(chalk_1.default.gray('This could mean:'));
189
+ console.log(chalk_1.default.gray(' • Your subscription has expired'));
190
+ console.log(chalk_1.default.gray(' • Your account was deleted'));
191
+ console.log(chalk_1.default.gray(' • The token was revoked\n'));
192
+ clearAuth();
193
+ lastValidationTime = 0; // Reset validation timer
194
+ // Fall through to re-prompt
195
+ }
196
+ }
197
+ catch (error) {
198
+ // Network error - allow offline usage with cached token
199
+ console.log(chalk_1.default.yellow('\n⚠️ Could not verify token (offline mode)'));
200
+ console.log(chalk_1.default.gray('Using cached credentials. Some features may be limited.\n'));
201
+ return config;
202
+ }
203
+ }
204
+ else {
205
+ // Token was validated recently (within the last hour) - skip validation
206
+ return config;
207
+ }
208
+ }
168
209
  }
210
+ // No valid token - prompt for authentication
169
211
  const success = await promptAuth();
170
212
  if (success) {
213
+ lastValidationTime = Date.now(); // Set validation time after successful auth
171
214
  return getAuthConfig();
172
215
  }
173
216
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapcommit/cli",
3
- "version": "3.8.0",
3
+ "version": "3.8.2",
4
4
  "description": "Instant AI commits. Beautiful progress tracking. Never write commit messages again.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {