BasicAuthAddon | wretch

interface BasicAuthAddon {
    basicAuth<T extends BasicAuthAddon, C, R, E>(
        this: T & Wretch<T, C, R, E>,
        username: string,
        password: string,
    ): this;
}

Methods

basicAuth

  • basicAuth<T extends BasicAuthAddon, C, R, E>(
        this: T & Wretch<T, C, R, E>,
        username: string,
        password: string,
    ): this

    Sets the Authorization header to Basic + . Additionally, allows using URLs with credentials in them.

    const user = "user"
    const pass = "pass"

    // Automatically sets the Authorization header to "Basic " + <base64 encoded credentials>
    wretch("...").addon(BasicAuthAddon).basicAuth(user, pass).get()

    // Allows using URLs with credentials in them
    wretch(`https://${user}:${pass}@...`).addon(BasicAuthAddon).get()

    Type Parameters

    Parameters

    • this: T & Wretch<T, C, R, E>
    • username: string

      Username to use for basic auth

    • password: string

      Password to use for basic auth

    Returns this