A solution without dependencies.
Node
headers.set('Authorization', 'Basic ' + Buffer.from(username + ":" + password).toString('base64'));
Browser
headers.set('Authorization', 'Basic ' + btoa(username + ":" + password));
More Related Contents:
- Trying to use fetch and pass in mode: no-cors
- Why does .json() return a promise?
- 5xx or 4xx error with “No ‘Access-Control-Allow-Origin’ header is present”
- Error when accessing API with fetch while setting mode to ‘no-cors’ [duplicate]
- How do I POST a x-www-form-urlencoded request using Fetch?
- React Native fetch() Network Request Failed
- How do I post form data with fetch api?
- How do I POST with multipart form data using fetch?
- Upload progress indicators for fetch?
- fetch: Reject promise with JSON error object
- fetch resolves even if 404?
- Returning HTML With fetch()
- using a fetch inside another fetch in javascript
- fetch – Missing boundary in multipart/form-data POST
- fetch() unexpected end of input
- Retrieve data from a ReadableStream object?
- What causes a Failed to execute ‘fetch’ on ‘ServiceWorkerGlobalScope’: ‘only-if-cached’ can be set only with ‘same-origin’ mode error?
- Why is the response object from JavaScript fetch API a promise?
- Intercept fetch() API requests and responses in JavaScript
- Cannot load Deezer API resources from localhost with the Fetch API
- Hide 401 console.error in chrome dev tools getting 401 on fetch() call [duplicate]
- Unable to fetch POST without no-cors in header
- Empty body in fetch POST request
- Javascript: Fetch DELETE and PUT requests
- how to process fetch response from an ‘opaque’ type?
- fetch retry request (on failure)
- UseEffect being called multiple times
- How to post image with fetch?
- React-native upload image to amazons s3
- How do I download a file from FastAPI backend using JavaScript Fetch API in the frontend?