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

harv-auth-kit

v0.0.1

Published

[![npm version](https://img.shields.io/npm/v/harv-auth-kit.svg)](https://www.npmjs.com/package/harv-auth-kit)

Readme

harv-auth-kit

npm version

Introduction

Installation

$ npm install @tanstack/react-query harv-auth-kit

Usage

To use this library, you will need to provide it with functions for fetching the current user, logging in, registering, and logging out. You can do this using the configureAuth function:

const { useUser, useLogin, useRegister, useLogout } = configureAuth({
  userFn: () => api.get('/me'),
  loginFn: (credentials) => api.post('/login', credentials),
  registerFn: (credentials) => api.post('/register', credentials),
  logoutFn: () => api.post('/logout'),
});

NOTE: All hooks and components must be used within QueryClientProvider

With these hooks you can then add authentication functionality in your app

Example:

  • You can use the useUser to get the user details
  • You can use the useLogout to logout the user
function UserInfo() {
  const user = useUser();
  const logout = useLogout();

  if (user.isLoading) {
    return <div>Loading ...</div>;
  }

  if (user.error) {
    return <div>{JSON.stringify(user.error, null, 2)}</div>;
  }

  if (!user.data) {
    return <div>Not logged in</div>;
  }

  return (
    <div>
      <div>Logged in as {user.data.email}</div>
      <button disabled={logout.isLoading} onClick={logout.mutate({})}>
        Log out
      </button>
    </div>
  );
}

In this way no need for storing and managing auth data and actions in a complex global state management

API Reference:

configureAuth

The configureAuth function takes a configuration object and returns a set of custom hooks for managing authentication.

Configuration Object Properties:

userFn: A function to retrieve the authenticated user. It should return a Promise resolving to the user object or null if unauthenticated.
loginFn: A function for logging in, accepting credentials and returning a Promise resolving to the user object.
registerFn: A function for registering a new user, accepting credentials and returning a Promise resolving to the new user object.
logoutFn: A function for logging out, returning a Promise that resolves when the logout action is completed.
userKey: An optional key for storing the authenticated user in the React Query cache, defaulting to ['authenticated-user'].

Returned Object Properties:

useUser: A hook to retrieve the authenticated user, wrapping around useQuery using the userFn and userKey from the configuration.
useLogin: A hook to log in the user, wrapping around useMutation using the loginFn. On success, it updates the authenticated user in the React Query cache.
useRegister: A hook to register a new user, wrapping around useMutation using the registerFn. On success, it updates the authenticated user in the cache.
useLogout: A hook to log out the user, wrapping around useMutation using the logoutFn. On success, it removes the authenticated user from the cache.

In this way, there's no need to manage authentication data and actions using a complex global state management system.