diff --git a/services/ui-src/src/utils/api/requestMethods/getRequestHeaders.ts b/services/ui-src/src/utils/api/requestMethods/getRequestHeaders.ts new file mode 100644 index 00000000..ba8eca88 --- /dev/null +++ b/services/ui-src/src/utils/api/requestMethods/getRequestHeaders.ts @@ -0,0 +1,14 @@ +import { Auth } from "aws-amplify"; + +export const getRequestHeaders = async (): Promise => { + try { + const session = await Auth.currentSession(); + const token = await session.getIdToken().getJwtToken(); + const headers = { + "x-api-key": token, + }; + return headers; + } catch (error) { + console.log(error); //eslint-disable-line no-console + } +}; diff --git a/services/ui-src/src/utils/api/requestMethods/getTemplateUrl.test.ts b/services/ui-src/src/utils/api/requestMethods/getTemplateUrl.test.ts new file mode 100644 index 00000000..0084ffe3 --- /dev/null +++ b/services/ui-src/src/utils/api/requestMethods/getTemplateUrl.test.ts @@ -0,0 +1,9 @@ +import { getSignedTemplateUrl } from "./getTemplateUrl"; + +const testTemplateName = "TestName"; + +describe("utils/getTemplateUrl", () => { + test("getSignedTemplateUrl()", () => { + expect(getSignedTemplateUrl(testTemplateName)).toBeTruthy(); + }); +}); diff --git a/services/ui-src/src/utils/api/requestMethods/getTemplateUrl.ts b/services/ui-src/src/utils/api/requestMethods/getTemplateUrl.ts new file mode 100644 index 00000000..cdb55cee --- /dev/null +++ b/services/ui-src/src/utils/api/requestMethods/getTemplateUrl.ts @@ -0,0 +1,12 @@ +import { API } from "aws-amplify"; +import { getRequestHeaders } from "./getRequestHeaders"; + +export async function getSignedTemplateUrl(templateName: string) { + const requestHeaders = await getRequestHeaders(); + const request = { + headers: { ...requestHeaders }, + }; + + const response = await API.get("hcbs", `/templates/${templateName}`, request); + return response; +}