Skip to content

Commit

Permalink
adding everything to try catch in auth
Browse files Browse the repository at this point in the history
  • Loading branch information
LordFarquaadtheCreator committed Aug 5, 2024
1 parent a73fa3e commit 11fd3b3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions middlewares/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { queryDatabase } from "routes/databaseFunctions";

const authorize = function () {
return async (req: any, res: any, next: any) => {
const name = req.headers.name.toLowerCase();
const key = req.headers.authorization?.split(" ")[1];
const query = {
text: "SELECT * FROM apikey WHERE name = $1 AND apikey = $2",
values: [name, key]
}
try {
const name = req.headers.name.toLowerCase();
const key = req.headers.authorization?.split(" ")[1];
const query = {
text: "SELECT * FROM apikey WHERE name = $1 AND apikey = $2",
values: [name, key]
}

if (!name || !key) {
return res.status(400).json({ message: "Please enter your name and key before accessing the database!" });
}
if (!name || !key) {
return res.status(400).json({ message: "Please enter your name and key before accessing the database!" });
}

try {
const result = await queryDatabase(req.client, query.text, query.values);
if (result.rows.length === 0) {
return res.status(401).json({ message: "Invalid name or key!" });
Expand Down

0 comments on commit 11fd3b3

Please sign in to comment.