Function: basicAuth()
basicAuth(
user,pass):BeforeRequestHook
Defined in: src/auth.ts:113
Returns a beforeRequest hook that adds an Authorization: Basic <credentials> header before every request. Credentials are encoded once at creation time.
The user:pass string is UTF-8 encoded before base64 (not btoa directly, which only supports Latin-1), so non-ASCII usernames/passwords are safe.
Parameters
user
string
The username (must not contain a colon).
pass
string
The password.
Returns
A beforeRequest hook that sets the Authorization header.
Example
ts
import valifetch from 'valifetch';
import { basicAuth } from 'valifetch/auth';
const api = valifetch.create({
hooks: { beforeRequest: [basicAuth('admin', 's3cr3t')] },
});