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-helper

v1.0.0

Published

A package that provides a ready-to-use authentication system for API-based applications.

Readme

Vue Auth Helper

A package that provides a ready-to-use authentication system for API-based applications.

This package works seamlessly with Laravel FineAuth.

What This Package Does

  • Stores your authentication state in a global reactive state.
  • Provides auth and guest route guards.
  • Provides login and logout helpers.
  • Tracks access token expiration.

What This Package Does Not Do

  • Create a login page.
  • Implement the authentication request to your API server.
  • Automatically attach the access token to request headers.
  • Automatically refresh the access token.
  • Automatically fetch the current user.

Installation

Install the package.

npm install vue-auth-helper

Install it into your Vue application.

import { createApp } from 'vue';
import vAuth from 'vue-auth-helper';

const app = createApp();

app.use(vAuth);

Register the route guards with your router instance.

  • redirectOnUnauthenticated specifies the path to redirect unauthenticated users to.
  • redirectOnAuthenticated specifies the path to redirect authenticated users to.
import { createRouter } from 'vue-router';
import { registerGuards } from 'vue-auth-helper';

const router = createRouter();

registerGuards(router, {
  redirectOnUnauthenticated: '/login',
  redirectOnAuthenticated: '/',
});

Guide

Login

You must implement your own API login flow.

After a successful login, your API should return the following values, then call the login helper.

  • token — a string.
  • user — an object.
  • expires_at (optional) — a Date, date string, or timestamp.
  • meta (optional) — an object.
import { login } from 'vue-auth-helper';

login(token, user, expires_at, meta);

After logging in, you must manually redirect the user to the home or dashboard page.

Protect Routes for Guests and Authenticated Users

Add auth: true to routes that require authentication.

const router = createRouter([
  {
    path: '/',
    name: 'dashboard',
    meta: {
      auth: true,
    },
  },
]);

Add guest: true to routes that should only be accessible to guests.

const router = createRouter([
  {
    path: '/login',
    name: 'login',
    meta: {
      guest: true,
    },
  },
]);

Load Current User

The current user and meta are stored in memory, so they are cleared when the page is refreshed.

You need to call your API's Get Current User endpoint when the application loads.

<script setup>
async function loadCurrentUser() {
  // ...
}

loadCurrentUser();
</script>

Refresh Token

The access token is stored in memory, so it is cleared when the page is refreshed.

You need to call your API's Refresh Token endpoint whenever the application loads.

<script setup>
async function refreshToken() {
  // ...
}

refreshToken();
</script>

Check the Login State

import { loggedIn } from 'vue-auth-helper';

loggedIn.value; // true | false

Check Whether the Access Token Has Expired

import { isExpired } from 'vue-auth-helper';

isExpired(); // true | false

Access Token

import { accessToken } from 'vue-auth-helper';

accessToken.value; // 'jdaosjdosa' | null

Current User and Meta

Access the current user through the read-only user computed value.

Access the meta object through the read-only meta computed value.

import { user, meta } from 'vue-auth-helper';

console.log(user.value);
console.log(meta.value);

Logout

import { logout } from 'vue-auth-helper';

logout();

After logging out, you must manually redirect the user to /login.