fixed 403 bug
This commit is contained in:
@@ -62,11 +62,8 @@ export async function authenticate(req, res, next) {
|
|||||||
}
|
}
|
||||||
} else if (apiKey) {
|
} else if (apiKey) {
|
||||||
try {
|
try {
|
||||||
await verifyAPIKey(apiKey).then((result) => {
|
await verifyAPIKey(apiKey);
|
||||||
if (result.valid) {
|
return next();
|
||||||
return next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch {
|
} catch {
|
||||||
return res.status(403).json({ message: "API Key invalid" }); // fix: don't chain after sendStatus
|
return res.status(403).json({ message: "API Key invalid" }); // fix: don't chain after sendStatus
|
||||||
}
|
}
|
||||||
@@ -79,7 +76,7 @@ async function verifyAPIKey(apiKey) {
|
|||||||
const result = await verifyAPIKeyDB(apiKey);
|
const result = await verifyAPIKeyDB(apiKey);
|
||||||
|
|
||||||
if (result.valid) {
|
if (result.valid) {
|
||||||
return { valid: true };
|
return;
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Invalid API Key");
|
throw new Error("Invalid API Key");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ dotenv.config();
|
|||||||
|
|
||||||
const pool = mysql
|
const pool = mysql
|
||||||
.createPool({
|
.createPool({
|
||||||
host: process.env.DB_HOST_2,
|
host: process.env.DB_HOST,
|
||||||
user: process.env.DB_USER_2,
|
user: process.env.DB_USER,
|
||||||
password: process.env.DB_PASSWORD_2,
|
password: process.env.DB_PASSWORD,
|
||||||
database: process.env.DB_NAME_2,
|
database: process.env.DB_NAME,
|
||||||
})
|
})
|
||||||
.promise();
|
.promise();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user