@armi-wave/common 1.23.43 → 1.23.45
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.
|
@@ -4,14 +4,26 @@ exports.currentUser = void 0;
|
|
|
4
4
|
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
5
5
|
const currentUser = (req, res, next) => {
|
|
6
6
|
var _a;
|
|
7
|
-
|
|
7
|
+
// Try to get JWT from session cookie first (for mobile)
|
|
8
|
+
let jwt = (_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt;
|
|
9
|
+
// If not in session, try Authorization header (for web)
|
|
10
|
+
if (!jwt) {
|
|
11
|
+
const authHeader = req.headers.authorization;
|
|
12
|
+
if (authHeader && authHeader.startsWith('Bearer ')) {
|
|
13
|
+
jwt = authHeader.substring(7); // Remove 'Bearer ' prefix
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// If no JWT found in either place, continue without auth
|
|
17
|
+
if (!jwt) {
|
|
8
18
|
return next();
|
|
9
19
|
}
|
|
10
20
|
try {
|
|
11
|
-
const payload = (0, jsonwebtoken_1.verify)(
|
|
21
|
+
const payload = (0, jsonwebtoken_1.verify)(jwt, process.env.JWT_KEY);
|
|
12
22
|
req.currentUser = payload;
|
|
13
23
|
}
|
|
14
|
-
catch (error) {
|
|
24
|
+
catch (error) {
|
|
25
|
+
// Invalid token, continue without auth
|
|
26
|
+
}
|
|
15
27
|
next();
|
|
16
28
|
};
|
|
17
29
|
exports.currentUser = currentUser;
|
|
@@ -2,7 +2,7 @@ import mongoose, { Document } from 'mongoose';
|
|
|
2
2
|
import { Mention } from './Mention';
|
|
3
3
|
interface TextPostReply extends Document {
|
|
4
4
|
textPostCommentId: mongoose.Types.ObjectId;
|
|
5
|
-
|
|
5
|
+
textPostId: mongoose.Types.ObjectId;
|
|
6
6
|
userId: mongoose.Types.ObjectId;
|
|
7
7
|
username: string;
|
|
8
8
|
profilePicUrl: string;
|
|
@@ -2,7 +2,7 @@ import mongoose, { Document } from 'mongoose';
|
|
|
2
2
|
import { Mention } from './Mention';
|
|
3
3
|
interface VideoPostReply extends Document {
|
|
4
4
|
videoPostCommentId: mongoose.Types.ObjectId;
|
|
5
|
-
|
|
5
|
+
videoPostId: mongoose.Types.ObjectId;
|
|
6
6
|
userId: mongoose.Types.ObjectId;
|
|
7
7
|
username: string;
|
|
8
8
|
profilePicUrl: string;
|