mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 14:17:13 +01:00
Add api validations.
This commit is contained in:
parent
7d5a24044a
commit
7a7233ead4
41 changed files with 690 additions and 180 deletions
|
|
@ -1,19 +1,20 @@
|
|||
import redis from '@umami/redis-client';
|
||||
import cors from 'cors';
|
||||
import debug from 'debug';
|
||||
import { getAuthToken, parseShareToken } from 'lib/auth';
|
||||
import { ROLES } from 'lib/constants';
|
||||
import { isUuid, secret } from 'lib/crypto';
|
||||
import { findSession } from 'lib/session';
|
||||
import {
|
||||
createMiddleware,
|
||||
unauthorized,
|
||||
badRequest,
|
||||
createMiddleware,
|
||||
parseSecureToken,
|
||||
tooManyRequest,
|
||||
unauthorized,
|
||||
} from 'next-basics';
|
||||
import debug from 'debug';
|
||||
import cors from 'cors';
|
||||
import redis from '@umami/redis-client';
|
||||
import { findSession } from 'lib/session';
|
||||
import { getAuthToken, parseShareToken } from 'lib/auth';
|
||||
import { secret, isUuid } from 'lib/crypto';
|
||||
import { ROLES } from 'lib/constants';
|
||||
import { getUserById } from '../queries';
|
||||
import { NextApiRequestCollect } from 'pages/api/send';
|
||||
import { getUserById } from '../queries';
|
||||
import { NextApiRequestQueryBody } from './types';
|
||||
|
||||
const log = debug('umami:middleware');
|
||||
|
||||
|
|
@ -75,3 +76,15 @@ export const useAuth = createMiddleware(async (req, res, next) => {
|
|||
|
||||
next();
|
||||
});
|
||||
|
||||
export const useValidate = createMiddleware(async (req: any, res, next) => {
|
||||
try {
|
||||
const { yup } = req as NextApiRequestQueryBody;
|
||||
|
||||
yup[req.method].validateSync({ ...req.query, ...req.body });
|
||||
} catch (e: any) {
|
||||
return badRequest(res, e.message);
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue