mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
login web endpoint fastify body schema validation (#2653)
* feat: add body schema validation to login endpoint #2623 When a request is made, the following error is displayed on log error--- Promise may not be fulfilled with 'undefined' when statusCode is not 204 https://github.com/fastify/fastify/pull/2702 * feat: add body schema validation to resetPassword endpoint Co-authored-by: Juan Picado <juanpicado19@gmail.com>
This commit is contained in:
parent
a88c72d0b2
commit
8246bb69b2
1 changed files with 91 additions and 57 deletions
|
@ -6,9 +6,36 @@ import { JWTSignOptions } from '@verdaccio/types';
|
|||
import { validatePassword } from '@verdaccio/utils';
|
||||
|
||||
const debug = buildDebug('verdaccio:api:login');
|
||||
const loginBodySchema = {
|
||||
body: {
|
||||
type: 'object',
|
||||
required: ['username', 'password'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
username: { type: 'string' },
|
||||
password: { type: 'string' },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const resetPasswordSchema = {
|
||||
body: {
|
||||
type: 'object',
|
||||
required: ['password'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
password: { type: 'string' },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async function loginRoute(fastify: FastifyInstance) {
|
||||
fastify.post('/login', async (request, reply) => {
|
||||
fastify.post(
|
||||
'/login',
|
||||
{
|
||||
schema: loginBodySchema,
|
||||
},
|
||||
async (request, reply) => {
|
||||
// @ts-expect-error
|
||||
const { username, password } = request.body;
|
||||
debug('authenticate %o', username);
|
||||
|
@ -29,9 +56,15 @@ async function loginRoute(fastify: FastifyInstance) {
|
|||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
fastify.put('/reset_password', async (request, reply) => {
|
||||
fastify.put(
|
||||
'/reset_password',
|
||||
{
|
||||
schema: resetPasswordSchema,
|
||||
},
|
||||
async (request, reply) => {
|
||||
if (_.isNil(request.userRemote.name)) {
|
||||
reply.send(
|
||||
fastify.errorUtils.getCode(
|
||||
|
@ -69,7 +102,8 @@ async function loginRoute(fastify: FastifyInstance) {
|
|||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
// });
|
||||
}
|
||||
export default loginRoute;
|
||||
|
|
Loading…
Reference in a new issue