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

@nordic-ui/asgardian-react

v0.2.0

Published

A simple authorization library

Readme

Overview

Asgardian React provides React-specific hooks and components to seamlessly integrate the Asgardian authorization library into your React applications. It offers a declarative way to handle permissions and access control in your React components.

Installation

npm install @nordic-ui/asgardian-react
yarn add @nordic-ui/asgardian-react
pnpm add @nordic-ui/asgardian-react

Note: @nordic-ui/asgardian is a peer dependency and must be installed alongside this package.

Quick Start

  1. Setup the Ability Provider Wrap your application with the AbilityProvider to make permissions available throughout your component tree:

    import { createAbility } from '@nordic-ui/asgardian';
    import { AbilityProvider } from '@nordic-ui/asgardian-react';
    
    const ability = createAbility();
    // Configure your ability with rules...
    
    const App = () => {
      return (
        <AbilityProvider ability={ability}>
          <YourAppComponents />
        </AbilityProvider>
      );
    }
  2. Use Hooks in Components

    • useAbility - Full Access to Ability Instance
      import { useAbility } from '@nordic-ui/asgardian-react';
      
      const UserProfile = () => {
        const { can, cannot } = useAbility();
      
        if (cannot('read', 'user')) {
          return <div>Access denied</div>;
        }
      
        return (
          <div>
            <h1>User Profile</h1>
            {can('edit', 'user') && (
              <button>Edit Profile</button>
            )}
          </div>
        );
      }
    • useCan - Check Single Permission
      import { useCan } from '@nordic-ui/asgardian-react';
      
      const EditButton = () => {
        const canEdit = useCan('edit', 'post');
      
        return canEdit ? <button>Edit Post</button> : null;
      }
    • useCannot - Check Denied Permission
      import { useCannot } from '@nordic-ui/asgardian-react';
      
      const AdminPanel = () => {
        const cannotAccess = useCannot('access', 'admin');
      
        if (cannotAccess) {
          return <div>Insufficient permissions</div>;
        }
      
        return <div>Admin Panel Content</div>;
      }

API Reference

Hooks

useAbility<TActions, TResources>()

Returns an object with permission checking methods that are memoized for performance.

Returns:
  • isAllowed(action, resource, conditions?) - Check if action is allowed
  • notAllowed(action, resource, conditions?) - Check if action is not allowed
  • can(action, resource, conditions?) - Alias for isAllowed
  • cannot(action, resource, conditions?) - Alias for notAllowed

useCan<TActions, TResources>(action, resource, conditions?)

Parameters:
  • action: TActions - The action to check
  • resource: TResources - The resource to check against
  • conditions?: Condition - Optional conditions
Returns:

boolean - Whether the action is allowed

useCannot<TActions, TResources>(action, resource, conditions?)

Parameters:
  • action: TActions - The action to check
  • resource: TResources - The resource to check against
  • conditions?: Condition - Optional conditions
Returns:

boolean - Whether the action is not allowed

TypeScript Support

All hooks support generic types for actions and resources:

type Actions = 'create' | 'read' | 'update' | 'delete';
type Resources = 'post' | 'user' | 'comment';

const { can } = useAbility<Actions, Resources>();
const canEdit = useCan<Actions, Resources>('update', 'post');

NOTE: If no custom actions are needed, either leave the generics empty or use the never type.

Examples

Conditional Rendering

const PostActions = ({ post }) => {
  const { can } = useAbility();

  return (
    <div>
      {can('edit', 'post', { userId: post.authorId }) && (
        <button>Edit</button>
      )}
      {can('delete', 'post', { userId: post.authorId }) && (
        <button>Delete</button>
      )}
    </div>
  );
}

Route Protection

import { useCannot } from '@nordic-ui/asgardian-react';

const ProtectedRoute = ({ children }) => {
  const cannotAccess = useCannot('access', 'admin');

  if (cannotAccess) {
    return <Navigate to="/unauthorized" />;
  }

  return children;
}

License

Asgardian React is licensed under the MIT license.

Author

Made by Kevin Østerkilde