@mtg-tracker/common 1.0.13 → 1.0.15
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.
|
@@ -29,6 +29,11 @@ function runMigrations(pool, migrationsDir, service) {
|
|
|
29
29
|
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
30
30
|
)
|
|
31
31
|
`);
|
|
32
|
+
// Check if migrations directory exists
|
|
33
|
+
if (!fs_1.default.existsSync(migrationsDir)) {
|
|
34
|
+
console.log(`No migrations directory found at ${migrationsDir}, skipping migrations...`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
32
37
|
// Get all migration files from the provided directory
|
|
33
38
|
const files = fs_1.default.readdirSync(migrationsDir)
|
|
34
39
|
.filter(file => file.endsWith('_up.sql'))
|
package/build/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export * from './errors/custom-error';
|
|
|
4
4
|
export * from './errors/request-validation-error';
|
|
5
5
|
export * from './middlewares/current-user';
|
|
6
6
|
export * from './middlewares/error-handler';
|
|
7
|
+
export * from './middlewares/require-auth';
|
|
7
8
|
export * from './middlewares/validate-request';
|
package/build/index.js
CHANGED
|
@@ -20,4 +20,5 @@ __exportStar(require("./errors/custom-error"), exports);
|
|
|
20
20
|
__exportStar(require("./errors/request-validation-error"), exports);
|
|
21
21
|
__exportStar(require("./middlewares/current-user"), exports);
|
|
22
22
|
__exportStar(require("./middlewares/error-handler"), exports);
|
|
23
|
+
__exportStar(require("./middlewares/require-auth"), exports);
|
|
23
24
|
__exportStar(require("./middlewares/validate-request"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
import { CustomError } from '../errors/custom-error';
|
|
3
|
+
export declare class NotAuthorizedError extends CustomError {
|
|
4
|
+
statusCode: number;
|
|
5
|
+
constructor();
|
|
6
|
+
serializeErrors(): {
|
|
7
|
+
message: string;
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
10
|
+
export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireAuth = exports.NotAuthorizedError = void 0;
|
|
4
|
+
const custom_error_1 = require("../errors/custom-error");
|
|
5
|
+
class NotAuthorizedError extends custom_error_1.CustomError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Not authorized');
|
|
8
|
+
this.statusCode = 401;
|
|
9
|
+
Object.setPrototypeOf(this, NotAuthorizedError.prototype);
|
|
10
|
+
}
|
|
11
|
+
serializeErrors() {
|
|
12
|
+
return [{ message: 'Not authorized' }];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.NotAuthorizedError = NotAuthorizedError;
|
|
16
|
+
const requireAuth = (req, res, next) => {
|
|
17
|
+
if (!req.currentUser) {
|
|
18
|
+
throw new NotAuthorizedError();
|
|
19
|
+
}
|
|
20
|
+
next();
|
|
21
|
+
};
|
|
22
|
+
exports.requireAuth = requireAuth;
|