npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vue-auth-href

v2.0.0

Published

Vue 3 directive and composable for downloading protected resources with authentication headers.

Readme

vue-auth-href

Breaking changes: 2.0.0 and later are not compatible with the previous 1.8.0 Vue 2 release. If you still need Vue 2 support, use version 1.8.0.

Vue 3 directive and composable for downloading protected resources with authentication headers.

vue-auth-href intercepts an anchor click, performs an authenticated GET, converts the response to a blob, and triggers the browser download flow. In 2.0.0, the library is rewritten for Vue 3, TypeScript, Vite+, and Vitest.

Install

pnpm add vue-auth-href vue

Plugin Usage

Register the plugin once and keep the token resolver in plugin options.

import { createApp } from "vue";
import App from "./App.vue";
import VueAuthHref from "vue-auth-href";

const app = createApp(App);

app.use(VueAuthHref, {
  token: () => localStorage.getItem("access_token"),
  headers: {
    "x-client": "dashboard",
  },
  loading: {
    text: "Downloading",
  },
});

app.mount("#app");

Then use the directive on any anchor:

<template>
  <a v-auth-href href="/api/reports/monthly.csv">Download report</a>
</template>

Inline directive options still override the plugin defaults:

<template>
  <a
    v-auth-href="{
      loading: {
        text: 'Preparing file',
        animateDots: false,
      },
    }"
    href="/api/reports/monthly.csv"
  >
    Download report
  </a>
</template>

Composable Usage

Use the composable when you want full control over the trigger element or UI state.

<script setup lang="ts">
import { useAuthDownload } from "vue-auth-href";

const { download, error, isDownloading, status } = useAuthDownload({
  token: () => localStorage.getItem("access_token"),
});

async function downloadReport() {
  await download({
    url: "/api/reports/monthly.csv",
    fileName: "monthly.csv",
  });
}
</script>

<template>
  <button :disabled="isDownloading" type="button" @click="downloadReport">
    {{ isDownloading ? "Downloading..." : "Download report" }}
  </button>

  <p v-if="status === 'error' && error">Download failed: {{ error.message }}</p>
</template>

API

AuthDownloadOptions

Shared options used by the composable and directive:

| Option | Type | Default | Description | | ------------------ | ----------------------------------------------------------------------------------- | ------------------ | ----------------------------------------------------------------------------- | | token | string \| Ref<string \| null \| undefined> \| (() => string \| null \| undefined) | - | Required unless provided by plugin or composable defaults. | | authHeader | string | "Authorization" | Header name used for the auth token. | | authScheme | string | "Bearer" | Prepended to the token as <scheme> <token>. Use "" to send the raw token. | | headers | Record<string, string> | {} | Extra request headers. | | request | Omit<RequestInit, "headers" \| "method"> | undefined | Extra fetch options such as credentials. | | fetcher | fetch-compatible function | globalThis.fetch | Override for testing or custom transports. | | fileName | string \| ((response, url) => string \| undefined) | undefined | Preferred file name before falling back to response headers or the URL. | | cleanupDelay | number | -1 | Delay before removing the generated blob link. | | onBeforeDownload | () => void \| Promise<void> | undefined | Invoked before the request starts. | | onSuccess | (result) => void | undefined | Invoked after a successful download. | | onError | (error) => void | undefined | Invoked with an AuthDownloadError. | | onSettled | (outcome) => void | undefined | Invoked after success or failure. |

AuthHrefDirectiveOptions

Directive options extend AuthDownloadOptions with a loading object:

| Option | Type | Default | Description | | ------------------------ | ------------------ | --------------- | ------------------------------------------------------- | | loading.mode | "text" \| "html" | "text" | Controls whether loading content uses text or raw HTML. | | loading.text | string | "Downloading" | Text shown while the request is in flight. | | loading.html | string | "" | HTML shown while the request is in flight. | | loading.animateDots | boolean | true | Adds the dot animation when loading.mode is "text". | | loading.replaceContent | boolean | true | Replaces the anchor content while downloading. |

useAuthDownload()

The composable returns:

  • status: idle | pending | success | error
  • isDownloading: readonly boolean ref
  • error: readonly AuthDownloadError | null ref
  • download(request, overrides?)
  • reset()

Exports

import VueAuthHref, {
  AuthDownloadError,
  createAuthHrefDirective,
  createAuthHrefPlugin,
  useAuthDownload,
  vAuthHref,
} from "vue-auth-href";

Development

pnpm install
pnpm run check
pnpm run test:run
pnpm run build

The project uses:

  • Vite+ for build, format, and toolchain orchestration
  • Vitest and @vue/test-utils for unit tests
  • TypeScript for the library source and public types

Migration

2.0.0 is a breaking release. See MIGRATION.md for the upgrade notes from the Vue 2 line.

License

MIT