Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/middleware/auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,20 +355,23 @@ export function requireSeller() {
};
}

export function requireAdmin(adminWallets: string[]) {
export function requireAdmin(adminWallets: string[] = []) {
return (req: Request, _res: Response, next: NextFunction): void => {
const user = (req as AuthenticatedRequest).user;
if (!user) {
next(new HttpError(401, "Authentication required"));
return;
}

if (!adminWallets.includes(user.stellarAddress)) {
next(new AppError(403, "Admin privileges required", "ADMIN_REQUIRED"));
if (
user.userType === UserType.ADMIN ||
(adminWallets.length > 0 && adminWallets.includes(user.stellarAddress))
) {
next();
return;
}

next();
next(new AppError(403, "Admin privileges required", "ADMIN_REQUIRED"));
};
}

Expand Down
7 changes: 4 additions & 3 deletions src/routes/accreditation.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function createAccreditationRouter({
auth,
async (req: WalletParamsRequest, res: Response, next: NextFunction) => {
try {
const { wallet } = req.params;
const wallet = String(req.params.wallet);
const accreditation = await accreditationService.getAccreditation(wallet);

res.json({
Expand All @@ -54,7 +54,7 @@ export function createAccreditationRouter({
requireAdmin(adminWallets),
async (req: WalletParamsRequest, res: Response, next: NextFunction) => {
try {
const { wallet } = req.params;
const wallet = String(req.params.wallet);
const { tier, verificationSource } = req.body;

if (!Object.values(AccreditationTier).includes(tier)) {
Expand Down Expand Up @@ -84,7 +84,8 @@ export function createAccreditationRouter({
auth,
async (req: WalletEligibilityParamsRequest, res: Response, next: NextFunction) => {
try {
const { wallet, invoiceId } = req.params;
const wallet = String(req.params.wallet);
const invoiceId = String(req.params.invoiceId);
const eligibility = await accreditationService.checkEligibility(
wallet,
invoiceId
Expand Down
2 changes: 1 addition & 1 deletion src/routes/secondary-market/price-history.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function createPriceHistoryRouter({
auth,
async (req: InvoicePriceHistoryRequest, res: Response, next: NextFunction) => {
try {
const { invoiceId } = req.params;
const invoiceId = String(req.params.invoiceId);
const range = (req.query.range as PriceRange) || "30d";

if (!["7d", "30d", "all"].includes(range)) {
Expand Down
Loading
Loading