Skip to content

Commit 913c328

Browse files
committed
fix: added Object.assign to only include auth header when credentials are valid
1 parent 48216c2 commit 913c328

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

templates/ords-remix-jwt-sample/app/utils/ORDSFetcher.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import { isServletError } from '../models/ServletError';
1919
*/
2020
async function ORDSFetcher(endpoint : string | URL, authCredentials: string) {
2121
let url;
22+
const headers = {
23+
'Content-Type': 'application/json',
24+
Accept: 'application/json',
25+
};
26+
Object.assign(headers, authCredentials && { Authorization: authCredentials });
2227
if (typeof endpoint === 'string') {
2328
try {
2429
url = new URL(endpoint);
@@ -35,11 +40,7 @@ async function ORDSFetcher(endpoint : string | URL, authCredentials: string) {
3540
url = endpoint;
3641
}
3742
const getItems = await fetch(url!, {
38-
headers: {
39-
'Content-Type': 'application/json',
40-
Accept: 'application/json',
41-
Authorization: authCredentials,
42-
},
43+
headers,
4344
});
4445
if (!getItems.ok) {
4546
const errorMessage = 'Something went wrong while trying to query one of our ORDS endpoints.';

0 commit comments

Comments
 (0)