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 🙏

© 2025 – Pkg Stats / Ryan Hefner

vormiaguardjs

v1.0.1

Published

Vormia Guard JS - A npm package for authentication and guard management with VormiaPHP laravel Backend application

Downloads

8

Readme

vormiaphp/vormiaguardjs

Laravel Sanctum-compatible frontend access control for React, Vue, Svelte, Qwik, Astro, and Solid.


VormiaGuardJS is designed to work seamlessly with Laravel backends, but secure access control requires backend support for:

  • Authenticated user info (/api/user)
  • Role and permission checks
  • Backend-driven access control (/api/can-access)
  • Guard/role middleware

VormiaGuardPHP is the official Laravel backend package that provides these endpoints and middleware. It ensures your frontend and backend are fully integrated for secure, role-based access control. If you use VormiaGuardJS with Laravel, install VormiaGuardPHP for best results.

Laravel Users: If you are using Laravel, check out the official VormiaGuard PHP package for backend integration:


  • Maintains Laravel session via Sanctum (cookies)
  • Authenticated user state (GET /api/user)
  • Route/component-level access control (roles, user presence)
  • SPA (React Router) and MPA (SEO-friendly) support
  • Uses VormiaQueryJS for all API calls

For backend setup, route registration, and middleware configuration, see the VormiaGuardPHP README for complete instructions.

For full documentation and usage examples, visit:

Installation

Install VormiaGuardJS and its peer dependencies:

npm install vormiaguardjs
npm install vormiaqueryjs
npm install zustand

Note:

  • vormiaqueryjs is a required peer dependency.
  • This package uses Zustand for state management.

Quick Start (React SPA)

import { createVormiaClient, createGuardClient } from "vormiaguardjs";

// 1. Setup VormiaQueryJS client
createVormiaClient({ baseURL: "http://localhost", withCredentials: true });

// 2. Setup VormiaGuardJS client
createGuardClient({
  apiBaseUrl: "http://localhost",
  mode: "spa", // or 'mpa'
  redirects: { onFail: "/login", onSuccess: "/" },
});

Protecting Routes (React)

import { VrmGuard } from "vormiaguardjs";

<VrmGuard roles={["admin"]} redirectTo="/login">
  <AdminDashboard />
</VrmGuard>;

Login/Logout Hooks (React)

import { useVrmLogin, useVrmLogout } from "vormiaguardjs";

const { login, isLoading, error } = useVrmLogin({ redirectTo: "/" });
const { logout } = useVrmLogout({ redirectTo: "/login" });

Multi-Framework Usage

Note: All main exports are available at the root of the package. If you need framework-specific adapters and they are not available at the root, check the documentation or request their export in future releases.

Vue

import { useVormiaGuard } from "vormiaguardjs";
const { user, isLoading, isAuthenticated } = useVormiaGuard();

Svelte

import { createVormiaGuardStore } from "vormiaguardjs";
const { user, isAuthenticated } = createVormiaGuardStore();

Qwik

import { useVormiaGuard } from "vormiaguardjs";
const { user, isAuthenticated } = useVormiaGuard();

Astro

import { useVormiaGuard } from "vormiaguardjs";
const { user, isAuthenticated } = useVormiaGuard();

Solid

import { createVormiaGuardResource } from "vormiaguardjs";
const [user, { isAuthenticated }] = createVormiaGuardResource();

Configuration

  • apiBaseUrl: Laravel API base URL
  • mode: 'spa' (React Router) or 'mpa' (window.location)
  • redirects: { onFail, onSuccess } for login/logout

Example: Login Page (React)

import { useVrmLogin } from "vormiaguardjs";

function LoginPage() {
  const { login, isLoading, error } = useVrmLogin({ redirectTo: "/" });
  const handleSubmit = (e) => {
    e.preventDefault();
    const form = e.target;
    login({
      email: form.email.value,
      password: form.password.value,
    });
  };
  return (
    <form onSubmit={handleSubmit}>
      <input name="email" />
      <input name="password" type="password" />
      <button type="submit" disabled={isLoading}>
        Login
      </button>
      {error && <div>{error.message}</div>}
    </form>
  );
}

Auth Store (Zustand)

import { useVrmAuthStore } from "vormiaguardjs";
const user = useVrmAuthStore((s) => s.user);

For Laravel + React Developers

  • No boilerplate for Sanctum session, user state, or role checks
  • Works with any Laravel backend using Sanctum
  • Not a form manager or UI library: just session, role, and access logic

Example Usage

See runnable example projects:

Single Page Application (SPA)

import { useVrmGuard } from "vormiaguardjs";

function App() {
  const { isAuthenticated, user, login, logout } = useVrmGuard();

  return (
    <div style={{ padding: 32, fontFamily: "sans-serif" }}>
      <h1>VormiaGuardJS SPA Example</h1>
      {isAuthenticated ? (
        <>
          <p>Welcome, {user.name}!</p>
          <button onClick={logout}>Logout</button>
        </>
      ) : (
        <button onClick={login}>Login</button>
      )}
    </div>
  );
}

Multi Page Application (MPA)

import { GuardClient } from "vormiaguardjs";

const guard = new GuardClient({
  endpoint: "/api/auth",
});

if (guard.isAuthenticated()) {
  // Render protected content
  document.getElementById("app").innerHTML = `Welcome, ${
    guard.getUser().name
  }! <button id="logout">Logout</button>`;
  document.getElementById("logout").onclick = () => guard.logout();
} else {
  // Render login button
  document.getElementById("app").innerHTML =
    '<button id="login">Login</button>';
  document.getElementById("login").onclick = () => guard.login();
}

License

MIT License

Copyright (c) 2025 Vormia