@riocrypto/common-server 1.0.2613 → 1.0.2615
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.
|
@@ -89,7 +89,7 @@ class SecretManagerClient {
|
|
|
89
89
|
if (this.env === common_1.RioEnv.Development) {
|
|
90
90
|
file = "dev-secrets";
|
|
91
91
|
}
|
|
92
|
-
else if (this.env === common_1.RioEnv.Sandbox
|
|
92
|
+
else if (this.env === common_1.RioEnv.Sandbox) {
|
|
93
93
|
file = "sandbox-secrets";
|
|
94
94
|
}
|
|
95
95
|
else if (this.env === common_1.RioEnv.Test) {
|
|
@@ -98,6 +98,12 @@ class SecretManagerClient {
|
|
|
98
98
|
else if (this.env === common_1.RioEnv.Production) {
|
|
99
99
|
file = "production-secrets";
|
|
100
100
|
}
|
|
101
|
+
else if (this.env === common_1.RioEnv.Local) {
|
|
102
|
+
file = "local-secrets";
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
throw new Error(`Invalid environment: ${this.env}`);
|
|
106
|
+
}
|
|
101
107
|
const maxRetries = 5;
|
|
102
108
|
let attempt = 0;
|
|
103
109
|
while (attempt < maxRetries) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
import { Mongoose } from "mongoose";
|
|
2
3
|
declare global {
|
|
3
4
|
namespace Express {
|
|
4
5
|
interface Request {
|
|
@@ -15,4 +16,4 @@ declare global {
|
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
|
-
export declare const authContextMiddleware: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
19
|
+
export declare const authContextMiddleware: (req: Request, res: Response, next: NextFunction, mongoose: Mongoose) => Promise<void>;
|
|
@@ -14,14 +14,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.authContextMiddleware = void 0;
|
|
16
16
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
17
|
-
const mongoose_1 = __importDefault(require("mongoose"));
|
|
18
17
|
const common_1 = require("@riocrypto/common");
|
|
19
18
|
const secret_manager_client_1 = require("../clients/secret-manager-client");
|
|
20
19
|
const admin_auth_1 = require("../models/admin-auth");
|
|
21
20
|
const auth_1 = require("../models/auth");
|
|
22
21
|
let cachedAdminSecret = null;
|
|
23
22
|
let cachedUserSecret = null;
|
|
24
|
-
const authContextMiddleware = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
const authContextMiddleware = (req, res, next, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
24
|
const { adminAccessToken, accessToken } = req.cookies;
|
|
26
25
|
if (adminAccessToken) {
|
|
27
26
|
try {
|
|
@@ -30,7 +29,7 @@ const authContextMiddleware = (req, res, next) => __awaiter(void 0, void 0, void
|
|
|
30
29
|
}
|
|
31
30
|
if (cachedAdminSecret) {
|
|
32
31
|
const decoded = jsonwebtoken_1.default.verify(adminAccessToken, cachedAdminSecret);
|
|
33
|
-
const AdminAuth = (0, admin_auth_1.buildAdminAuth)(
|
|
32
|
+
const AdminAuth = (0, admin_auth_1.buildAdminAuth)(mongoose);
|
|
34
33
|
const adminAuth = yield AdminAuth.findById(decoded.id);
|
|
35
34
|
if (adminAuth) {
|
|
36
35
|
req.adminContext = {
|
|
@@ -50,7 +49,7 @@ const authContextMiddleware = (req, res, next) => __awaiter(void 0, void 0, void
|
|
|
50
49
|
}
|
|
51
50
|
if (cachedUserSecret) {
|
|
52
51
|
const decoded = jsonwebtoken_1.default.verify(accessToken, cachedUserSecret);
|
|
53
|
-
const Auth = (0, auth_1.buildAuth)(
|
|
52
|
+
const Auth = (0, auth_1.buildAuth)(mongoose);
|
|
54
53
|
const auth = yield Auth.findById(decoded.id);
|
|
55
54
|
if (auth) {
|
|
56
55
|
req.userContext = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2615",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@google-cloud/secret-manager": "^5.3.0",
|
|
29
29
|
"@google-cloud/storage": "^6.9.5",
|
|
30
30
|
"@hyperdx/node-opentelemetry": "^0.7.0",
|
|
31
|
-
"@riocrypto/common": "^1.0.
|
|
31
|
+
"@riocrypto/common": "^1.0.2414",
|
|
32
32
|
"@types/express": "^4.17.13",
|
|
33
33
|
"axios": "^1.7.4",
|
|
34
34
|
"crypto-js": "^4.2.0",
|