diff options
Diffstat (limited to 'packages/demobank-ui/src/utils.ts')
-rw-r--r-- | packages/demobank-ui/src/utils.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/packages/demobank-ui/src/utils.ts b/packages/demobank-ui/src/utils.ts index b8e0a2acb..23cade0e8 100644 --- a/packages/demobank-ui/src/utils.ts +++ b/packages/demobank-ui/src/utils.ts @@ -52,3 +52,18 @@ export function undefinedIfEmpty<T extends object>(obj: T): T | undefined { ? obj : undefined; } + +/** + * Craft headers with Authorization and Content-Type. + */ +export function prepareHeaders(username?: string, password?: string): Headers { + const headers = new Headers(); + if (username && password) { + headers.append( + "Authorization", + `Basic ${window.btoa(`${username}:${password}`)}`, + ); + } + headers.append("Content-Type", "application/json"); + return headers; +} |