omnibiofex 2.8.4 → 2.8.5
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/auth.js +62 -1
- package/src/commands/account.js +2 -2
- package/src/commands/earnings.js +2 -2
- package/src/commands/morning.js +2 -2
- package/src/commands/publish.js +2 -2
- package/src/firebase.js +4 -102
package/package.json
CHANGED
package/src/auth.js
CHANGED
|
@@ -351,4 +351,65 @@ async function getAuthToken() {
|
|
|
351
351
|
return token;
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
-
|
|
354
|
+
// ==================== USER EXTRACTION FUNCTIONS ====================
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Decode base64url to string (handles JWT format)
|
|
358
|
+
*/
|
|
359
|
+
function base64UrlDecode(str) {
|
|
360
|
+
let base64 = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
361
|
+
while (base64.length % 4) {
|
|
362
|
+
base64 += '=';
|
|
363
|
+
}
|
|
364
|
+
return Buffer.from(base64, 'base64').toString('utf8');
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Decode JWT token to extract user info
|
|
369
|
+
*/
|
|
370
|
+
function decodeToken() {
|
|
371
|
+
const token = config.get('authToken'); // fixed key name
|
|
372
|
+
if (!token) return null;
|
|
373
|
+
|
|
374
|
+
try {
|
|
375
|
+
const parts = token.split('.');
|
|
376
|
+
if (parts.length !== 3) return null;
|
|
377
|
+
|
|
378
|
+
const payload = parts[1];
|
|
379
|
+
const decoded = base64UrlDecode(payload);
|
|
380
|
+
const data = JSON.parse(decoded);
|
|
381
|
+
|
|
382
|
+
return {
|
|
383
|
+
uid: data.user_id || data.sub,
|
|
384
|
+
email: data.email,
|
|
385
|
+
exp: data.exp
|
|
386
|
+
};
|
|
387
|
+
} catch (error) {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Get current user UID from stored token
|
|
394
|
+
*/
|
|
395
|
+
function getCurrentUserUid() {
|
|
396
|
+
const decoded = decodeToken();
|
|
397
|
+
return decoded ? decoded.uid : null;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Get current user email from stored token
|
|
402
|
+
*/
|
|
403
|
+
function getCurrentUserEmail() {
|
|
404
|
+
const decoded = decodeToken();
|
|
405
|
+
return decoded ? decoded.email : null;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
module.exports = {
|
|
409
|
+
login,
|
|
410
|
+
logout,
|
|
411
|
+
getAuthToken,
|
|
412
|
+
isAuthenticated,
|
|
413
|
+
getCurrentUserUid,
|
|
414
|
+
getCurrentUserEmail
|
|
415
|
+
};
|
package/src/commands/account.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const chalk = require('chalk');
|
|
2
2
|
const open = require('open');
|
|
3
|
-
const { getAuthToken, isAuthenticated } = require('../auth');
|
|
4
|
-
const { db
|
|
3
|
+
const { getAuthToken, isAuthenticated, getCurrentUserUid, getCurrentUserEmail } = require('../auth');
|
|
4
|
+
const { db } = require('../firebase');
|
|
5
5
|
const { PremiumSpinner, sleep } = require('../utils/display');
|
|
6
6
|
const { collection, query, where, getDocs } = require('firebase/firestore');
|
|
7
7
|
|
package/src/commands/earnings.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const chalk = require('chalk');
|
|
2
|
-
const { isAuthenticated } = require('../auth');
|
|
3
|
-
const { db
|
|
2
|
+
const { isAuthenticated, getCurrentUserUid, getCurrentUserEmail } = require('../auth');
|
|
3
|
+
const { db } = require('../firebase');
|
|
4
4
|
const { PremiumSpinner, sleep } = require('../utils/display');
|
|
5
5
|
const { collection, query, where, orderBy, limit, getDocs } = require('firebase/firestore');
|
|
6
6
|
|
package/src/commands/morning.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const chalk = require('chalk');
|
|
2
|
-
const { isAuthenticated } = require('../auth');
|
|
3
|
-
const { db
|
|
2
|
+
const { isAuthenticated, getCurrentUserUid, getCurrentUserEmail } = require('../auth');
|
|
3
|
+
const { db } = require('../firebase');
|
|
4
4
|
const { PremiumSpinner, sleep } = require('../utils/display');
|
|
5
5
|
const { collection, query, where, orderBy, limit, getDocs } = require('firebase/firestore');
|
|
6
6
|
|
package/src/commands/publish.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const chalk = require('chalk');
|
|
2
2
|
const inquirer = require('inquirer');
|
|
3
|
-
const { getAuthToken, isAuthenticated } = require('../auth');
|
|
4
|
-
const { db
|
|
3
|
+
const { getAuthToken, isAuthenticated, getCurrentUserUid, getCurrentUserEmail } = require('../auth');
|
|
4
|
+
const { db } = require('../firebase');
|
|
5
5
|
const { PremiumSpinner, sleep } = require('../utils/display');
|
|
6
6
|
const { collection, query, where, orderBy, limit, getDocs, doc, updateDoc } = require('firebase/firestore');
|
|
7
7
|
|
package/src/firebase.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const { initializeApp, getApps } = require('firebase/app');
|
|
2
2
|
const { getAuth } = require('firebase/auth');
|
|
3
3
|
const { getFirestore } = require('firebase/firestore');
|
|
4
|
-
const Conf = require('conf');
|
|
5
4
|
|
|
6
5
|
const firebaseConfig = {
|
|
7
6
|
apiKey: "AIzaSyDlgXId4pLlYqm-MDuhfz3dLH24KBRHkw8",
|
|
@@ -23,110 +22,13 @@ if (getApps().length === 0) {
|
|
|
23
22
|
const auth = getAuth(app);
|
|
24
23
|
const db = getFirestore(app);
|
|
25
24
|
|
|
26
|
-
//
|
|
27
|
-
const
|
|
28
|
-
projectName: 'omnibiofex',
|
|
29
|
-
schema: {
|
|
30
|
-
token: { type: 'string' },
|
|
31
|
-
refreshToken: { type: 'string' },
|
|
32
|
-
expiresAt: { type: 'number' }
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Decode base64url to string (handles JWT format)
|
|
38
|
-
* @param {string} str - Base64url encoded string
|
|
39
|
-
* @returns {string} - Decoded string
|
|
40
|
-
*/
|
|
41
|
-
function base64UrlDecode(str) {
|
|
42
|
-
// Replace URL-safe characters with standard base64
|
|
43
|
-
let base64 = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
44
|
-
// Add padding if needed
|
|
45
|
-
while (base64.length % 4) {
|
|
46
|
-
base64 += '=';
|
|
47
|
-
}
|
|
48
|
-
return Buffer.from(base64, 'base64').toString('utf8');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Decode JWT token to extract user info
|
|
53
|
-
* @returns {Object|null} - { uid, email, exp } or null if no token
|
|
54
|
-
*/
|
|
55
|
-
function decodeToken() {
|
|
56
|
-
const token = tokenStore.get('token');
|
|
57
|
-
if (!token) return null;
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
// JWT format: header.payload.signature
|
|
61
|
-
const parts = token.split('.');
|
|
62
|
-
if (parts.length !== 3) {
|
|
63
|
-
console.error('Invalid JWT format: expected 3 parts, got', parts.length);
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Decode payload (base64url)
|
|
68
|
-
const payload = parts[1];
|
|
69
|
-
const decoded = base64UrlDecode(payload);
|
|
70
|
-
const data = JSON.parse(decoded);
|
|
71
|
-
|
|
72
|
-
// Firebase tokens use 'user_id' or 'sub' for UID
|
|
73
|
-
const uid = data.user_id || data.sub;
|
|
74
|
-
|
|
75
|
-
if (!uid) {
|
|
76
|
-
console.error('No user_id or sub found in token payload');
|
|
77
|
-
console.error('Token payload keys:', Object.keys(data));
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
uid: uid,
|
|
83
|
-
email: data.email,
|
|
84
|
-
exp: data.exp
|
|
85
|
-
};
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error('Token decode error:', error.message);
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Get current user UID from stored token
|
|
94
|
-
* @returns {string|null} - User UID or null
|
|
95
|
-
*/
|
|
96
|
-
function getCurrentUserUid() {
|
|
97
|
-
const decoded = decodeToken();
|
|
98
|
-
return decoded ? decoded.uid : null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Get current user email from stored token
|
|
103
|
-
* @returns {string|null} - User email or null
|
|
104
|
-
*/
|
|
105
|
-
function getCurrentUserEmail() {
|
|
106
|
-
const decoded = decodeToken();
|
|
107
|
-
return decoded ? decoded.email : null;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Check if token is valid (not expired)
|
|
112
|
-
* @returns {boolean}
|
|
113
|
-
*/
|
|
114
|
-
function isTokenValid() {
|
|
115
|
-
const decoded = decodeToken();
|
|
116
|
-
if (!decoded || !decoded.exp) return false;
|
|
117
|
-
|
|
118
|
-
// JWT exp is in seconds, Date.now() is in milliseconds
|
|
119
|
-
const now = Math.floor(Date.now() / 1000);
|
|
120
|
-
return decoded.exp > now;
|
|
121
|
-
}
|
|
25
|
+
// Re-export user functions from auth.js (single source of truth)
|
|
26
|
+
const { getCurrentUserUid, getCurrentUserEmail } = require('./auth');
|
|
122
27
|
|
|
123
28
|
module.exports = {
|
|
124
29
|
app,
|
|
125
30
|
auth,
|
|
126
|
-
db,
|
|
127
|
-
tokenStore,
|
|
128
|
-
decodeToken,
|
|
31
|
+
db,
|
|
129
32
|
getCurrentUserUid,
|
|
130
|
-
getCurrentUserEmail
|
|
131
|
-
isTokenValid
|
|
33
|
+
getCurrentUserEmail
|
|
132
34
|
};
|