mirror of
https://github.com/PretendoNetwork/BOSS.git
synced 2026-04-26 00:13:57 -05:00
Revert "refactor: remove authentication middleware - unneeded and caused eslint to complain"
This reverts commit ab0a6cc151.
This commit is contained in:
parent
9bebbe6e05
commit
eb2585d33b
11
src/middleware/authentication.ts
Normal file
11
src/middleware/authentication.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { getNEXDataByPID } from '@/util';
|
||||||
|
import type express from 'express';
|
||||||
|
|
||||||
|
export default async function authenticationMiddleware(request: express.Request, response: express.Response, next: express.NextFunction): Promise<void> {
|
||||||
|
if (request.pid) {
|
||||||
|
// TODO - Get users PNIDs
|
||||||
|
request.nexAccount = await getNEXDataByPID(request.pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ import RequestException from '@/request-exception';
|
||||||
import { LOG_INFO, LOG_SUCCESS } from '@/logger';
|
import { LOG_INFO, LOG_SUCCESS } from '@/logger';
|
||||||
import { config } from '@/config-manager';
|
import { config } from '@/config-manager';
|
||||||
import parseUserAgentMiddleware from '@/middleware/parse-user-agent';
|
import parseUserAgentMiddleware from '@/middleware/parse-user-agent';
|
||||||
|
import authenticationMiddleware from '@/middleware/authentication';
|
||||||
import nppl from '@/services/nppl';
|
import nppl from '@/services/nppl';
|
||||||
import npts from '@/services/npts';
|
import npts from '@/services/npts';
|
||||||
import npdi from '@/services/npdi';
|
import npdi from '@/services/npdi';
|
||||||
|
|
@ -28,6 +29,7 @@ app.use(express.urlencoded({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
app.use(parseUserAgentMiddleware);
|
app.use(parseUserAgentMiddleware);
|
||||||
|
app.use(authenticationMiddleware);
|
||||||
|
|
||||||
app.use(nppl);
|
app.use(nppl);
|
||||||
app.use(npts);
|
app.use(npts);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import express from 'express';
|
||||||
import subdomain from 'express-subdomain';
|
import subdomain from 'express-subdomain';
|
||||||
import Dicer from 'dicer';
|
import Dicer from 'dicer';
|
||||||
import { getDuplicateCECData, getRandomCECData } from '@/database';
|
import { getDuplicateCECData, getRandomCECData } from '@/database';
|
||||||
import { getFriends, getNEXDataByPID } from '@/util';
|
import { getFriends } from '@/util';
|
||||||
import { CECData } from '@/models/cec-data';
|
import { CECData } from '@/models/cec-data';
|
||||||
import { CECSlot } from '@/models/cec-slot';
|
import { CECSlot } from '@/models/cec-slot';
|
||||||
import { SendMode } from '@/types/common/spr-slot';
|
import { SendMode } from '@/types/common/spr-slot';
|
||||||
|
|
@ -70,19 +70,13 @@ spr.post('/relay/0', multipartParser, async (request, response) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!request.pid) {
|
if (!request.pid || !request.nexAccount) {
|
||||||
response.sendStatus(400);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const nexAccount = await getNEXDataByPID(request.pid);
|
|
||||||
if (!nexAccount) {
|
|
||||||
response.sendStatus(400);
|
response.sendStatus(400);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// * Check that the account is a 3DS and isn't banned
|
// * Check that the account is a 3DS and isn't banned
|
||||||
if (!nexAccount.friendCode || nexAccount.accessLevel < 0) {
|
if (!request.nexAccount.friendCode || request.nexAccount.accessLevel < 0) {
|
||||||
response.sendStatus(400);
|
response.sendStatus(400);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
13
src/types/express.d.ts
vendored
13
src/types/express.d.ts
vendored
|
|
@ -1,6 +1,11 @@
|
||||||
declare namespace Express {
|
import type { GetNEXDataResponse } from '@pretendonetwork/grpc/account/get_nex_data_rpc';
|
||||||
interface Request {
|
|
||||||
files?: Record<string, any>;
|
declare global {
|
||||||
pid: number;
|
namespace Express {
|
||||||
|
interface Request {
|
||||||
|
files?: Record<string, any>;
|
||||||
|
pid: number;
|
||||||
|
nexAccount: GetNEXDataResponse | null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user