Scanauth return objects
This commit is contained in:
parent
486e450a58
commit
46b7aceb0b
|
@ -15,14 +15,14 @@ import authchecker from './authchecker';
|
|||
const ScanAuth = async (req: Request, res: Response, next: () => void) => {
|
||||
let provided_token: string = req.headers["authorization"];
|
||||
if (provided_token == "" || provided_token === undefined || provided_token === null) {
|
||||
res.status(401).send("No api token provided.");
|
||||
res.status(401).send({ http_code: 401, short: "no_token", message: "No api token provided." });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
provided_token = provided_token.replace("Bearer ", "");
|
||||
} catch (error) {
|
||||
res.status(401).send("No valid jwt or api token provided.");
|
||||
res.status(401).send({ http_code: 401, short: "no_token", message: "No valid jwt or api token provided." });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ const ScanAuth = async (req: Request, res: Response, next: () => void) => {
|
|||
}
|
||||
finally {
|
||||
if (prefix == "" || prefix == undefined || prefix == null) {
|
||||
res.status(401).send("Api token non-existent or invalid syntax.");
|
||||
res.status(401).send({ http_code: 401, short: "invalid_token", message: "Api token non-existent or invalid syntax." });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ const ScanAuth = async (req: Request, res: Response, next: () => void) => {
|
|||
}
|
||||
finally {
|
||||
if (user_authorized == false) {
|
||||
res.status(401).send("Api token non-existent or invalid syntax.");
|
||||
res.status(401).send({ http_code: 401, short: "invalid_token", message: "Api token non-existent or invalid syntax." });
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
@ -56,10 +56,10 @@ const ScanAuth = async (req: Request, res: Response, next: () => void) => {
|
|||
}
|
||||
else {
|
||||
if (station.enabled == false) {
|
||||
res.status(401).send("Station disabled.");
|
||||
res.status(401).send({ http_code: 401, short: "station_disabled", message: "Station is disabled." });
|
||||
}
|
||||
if (!(await argon2.verify(station.key, provided_token))) {
|
||||
res.status(401).send("Api token invalid.");
|
||||
res.status(401).send({ http_code: 401, short: "invalid_token", message: "Api token non-existent or invalid syntax." });
|
||||
return;
|
||||
}
|
||||
req.headers["station_id"] = station.id.toString();
|
||||
|
|
Loading…
Reference in New Issue