-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_token.js
More file actions
28 lines (24 loc) · 962 Bytes
/
check_token.js
File metadata and controls
28 lines (24 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const fs = require('fs');
const path = require('path');
const envPath = path.resolve(process.cwd(), '.env.local');
const envContent = fs.readFileSync(envPath, 'utf8');
const match = envContent.match(/GROWW_API_KEY="?([^"\n]+)"?/);
const jwt = match ? match[1] : '';
if (!jwt || !jwt.startsWith('eyJ')) {
console.log('Not a JWT token or not found');
process.exit(0);
}
try {
const parts = jwt.split('.');
if (parts.length !== 3) throw new Error('Invalid JWT format');
const payload = JSON.parse(Buffer.from(parts[1], 'base64').toString());
console.log('Token Payload:', JSON.stringify(payload, null, 2));
if (payload.exp) {
const expDate = new Date(payload.exp * 1000);
console.log('Expiry Date:', expDate.toString());
console.log('Current Date:', new Date().toString());
console.log('Is Expired:', new Date() > expDate);
}
} catch (e) {
console.error('Error decoding token:', e.message);
}