Fix client hash signing via authenticated endpoint
This commit is contained in:
@@ -3,6 +3,26 @@ import { BASE_URL } from "../core/env";
|
||||
import { consoleLogger } from "../core/logger";
|
||||
import { hashAPIPath } from "../core/hash";
|
||||
|
||||
const buildHashedQueryUrl = async (queryUrl) => {
|
||||
try {
|
||||
const signRes = await axios.get(
|
||||
"/api/endpoint/gethash_api?path=" + encodeURIComponent(queryUrl)
|
||||
);
|
||||
|
||||
if (!signRes?.data?.hash) {
|
||||
throw new Error("Hash signature unavailable");
|
||||
}
|
||||
|
||||
return queryUrl + signRes.data.hash;
|
||||
} catch (error) {
|
||||
if (typeof window === "undefined" && process.env.HASHKEY) {
|
||||
return queryUrl + hashAPIPath(queryUrl);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const getMyCases = (loggedInUserId) => {
|
||||
return axios
|
||||
.get(
|
||||
@@ -234,8 +254,11 @@ export const sendCaseCompleteMessage = async (
|
||||
"&tempcaseref=" +
|
||||
caseReference +
|
||||
"&inv=" +
|
||||
inv +
|
||||
hashAPIPath(hashQueryPath);
|
||||
inv;
|
||||
|
||||
var signedQueryUrl = await buildHashedQueryUrl(hashQueryPath);
|
||||
|
||||
queryUrl = queryUrl + signedQueryUrl.replace(hashQueryPath, "");
|
||||
|
||||
var config = {
|
||||
method: "get",
|
||||
@@ -288,7 +311,7 @@ export const sendRepCompleteMessage = async (
|
||||
"&repid=" +
|
||||
fileName;
|
||||
|
||||
var queryUrl = hashQueryPath + hashAPIPath(hashQueryPath);
|
||||
var queryUrl = await buildHashedQueryUrl(hashQueryPath);
|
||||
|
||||
var config = {
|
||||
method: "get",
|
||||
|
||||
Reference in New Issue
Block a user