-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rocio De Santiago
authored and
Rocio De Santiago
committed
Aug 2, 2024
1 parent
04e526a
commit f43e6e3
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
services/ui-src/src/utils/api/requestMethods/getRequestHeaders.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Auth } from "aws-amplify"; | ||
|
||
export const getRequestHeaders = async (): Promise<any> => { | ||
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 | ||
} | ||
}; |
9 changes: 9 additions & 0 deletions
9
services/ui-src/src/utils/api/requestMethods/getTemplateUrl.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { getSignedTemplateUrl } from "./getTemplateUrl"; | ||
|
||
const testTemplateName = "TestName"; | ||
|
||
describe("utils/getTemplateUrl", () => { | ||
test("getSignedTemplateUrl()", () => { | ||
expect(getSignedTemplateUrl(testTemplateName)).toBeTruthy(); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
services/ui-src/src/utils/api/requestMethods/getTemplateUrl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |