@duvdu-v1/duvdu 1.1.147 → 1.1.149
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.
|
@@ -52,26 +52,36 @@ const isauthenticated = (req, res, next) => __awaiter(void 0, void 0, void 0, fu
|
|
|
52
52
|
en: `Forbidden: User is blocked ${req.loggedUser.isBlocked.reason}`,
|
|
53
53
|
ar: ` ممنوع: المستخدم محظور ${req.loggedUser.isBlocked.reason}`,
|
|
54
54
|
}, req.lang));
|
|
55
|
+
next();
|
|
55
56
|
}
|
|
56
57
|
catch (error) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
58
|
+
try {
|
|
59
|
+
const payload = (0, jsonwebtoken_1.verify)(req.session.refresh, process.env.JWT_KEY);
|
|
60
|
+
const user = yield User_model_1.Users.findById(payload.id);
|
|
61
|
+
if (!user)
|
|
62
|
+
return res.status(423).json({ message: 'token expired' });
|
|
63
|
+
if (user.isBlocked.value)
|
|
64
|
+
return next(new unauthorized_error_1.UnauthorizedError({
|
|
65
|
+
en: `Forbidden: User is blocked ${req.loggedUser.isBlocked.reason}`,
|
|
66
|
+
ar: ` ممنوع: المستخدم محظور ${req.loggedUser.isBlocked.reason}`,
|
|
67
|
+
}, req.lang));
|
|
68
|
+
const role = yield Role_model_1.Roles.findById(user.role);
|
|
69
|
+
if (!role)
|
|
70
|
+
return res.status(423).json({ message: 'invalid role' });
|
|
71
|
+
const accessToken = (0, exports.generateAccessToken)({
|
|
72
|
+
id: user.id,
|
|
73
|
+
isVerified: user.isVerified,
|
|
74
|
+
isBlocked: user.isBlocked,
|
|
75
|
+
role: { key: role.key, permissions: role.permissions },
|
|
76
|
+
});
|
|
77
|
+
req.session.access = accessToken;
|
|
78
|
+
req.loggedUser = (0, jsonwebtoken_1.verify)(accessToken, process.env.JWT_KEY);
|
|
79
|
+
next();
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return res.status(423).json({ message: 'token expired' });
|
|
83
|
+
}
|
|
73
84
|
}
|
|
74
|
-
next();
|
|
75
85
|
});
|
|
76
86
|
exports.isauthenticated = isauthenticated;
|
|
77
87
|
const generateAccessToken = (payload) => jsonwebtoken_1.default.sign(payload, process.env.JWT_KEY, {
|
|
@@ -25,7 +25,7 @@ const userSchema = new mongoose_1.Schema({
|
|
|
25
25
|
password: String,
|
|
26
26
|
verificationCode: { code: String, expireAt: Date, reason: { type: String, default: null } },
|
|
27
27
|
isVerified: { type: Boolean, default: false },
|
|
28
|
-
token: String,
|
|
28
|
+
refreshTokens: [{ token: { type: String, default: null }, fingerprint: { type: String, default: null }, clientType: { type: String, default: null } }],
|
|
29
29
|
profileImage: { type: String, default: 'defaults/profile.jpg' },
|
|
30
30
|
coverImage: { type: String, default: null },
|
|
31
31
|
location: { lat: { type: Number, default: null }, lng: { type: Number, default: null } },
|
package/build/types/User.d.ts
CHANGED
|
@@ -53,7 +53,11 @@ export interface Iuser {
|
|
|
53
53
|
reason?: VerificationReason;
|
|
54
54
|
};
|
|
55
55
|
isVerified: boolean;
|
|
56
|
-
|
|
56
|
+
refreshTokens?: {
|
|
57
|
+
fingerprint: string;
|
|
58
|
+
clientType: string;
|
|
59
|
+
token: string;
|
|
60
|
+
}[];
|
|
57
61
|
profileImage?: string;
|
|
58
62
|
coverImage?: string;
|
|
59
63
|
location?: {
|