Skip to content

Commit

Permalink
added api key formats to all sql operations
Browse files Browse the repository at this point in the history
  • Loading branch information
vignesha22 committed Feb 28, 2024
1 parent 391ad3e commit 3be94dd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/src/routes/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ const adminRoutes: FastifyPluginAsync = async (server) => {
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY });
if (!body.API_KEY)
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_DATA });
if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*-_&])[A-Za-z\d@$!%*-_&]{8,}$/.test(body.API_KEY))
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.API_KEY_VALIDATION_FAILED })
const result: any[] = await new Promise((resolve, reject) => {
server.sqlite.db.get("SELECT * FROM api_keys WHERE API_KEY=?", [body.API_KEY], (err: any, row: any) => {
if (err) reject(err);
Expand Down Expand Up @@ -164,6 +166,8 @@ const adminRoutes: FastifyPluginAsync = async (server) => {
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY });
if (!body.API_KEY)
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_DATA });
if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*-_&])[A-Za-z\d@$!%*-_&]{8,}$/.test(body.API_KEY))
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.API_KEY_VALIDATION_FAILED })
await new Promise((resolve, reject) => {
server.sqlite.db.run("DELETE FROM api_keys WHERE API_KEY=?", [body.API_KEY], (err: any, rows: any) => {
if (err) reject(err);
Expand Down

0 comments on commit 3be94dd

Please sign in to comment.