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

@kendevelops/auth-flow-kit

v1.0.6

Published

A lightweight authentication toolkit for **React** and **Next.js 13–16 (App Router)** that extends beyond tools like **ReduxToolkit** and **Zustand** style global state management for authentication, as it also comes with prebuilt UI screens and a globall

Readme

@kendevelops/auth-flow-kit

A lightweight authentication toolkit for React and Next.js 13–16 (App Router) that extends beyond tools like ReduxToolkit and Zustand style global state management for authentication, as it also comes with prebuilt UI screens and a globally accessible useAuth() hook.

⭐ What This Library Really Is

auth-flow-kit is not a traditional backend-driven auth framework:

  • Authentication state is global
  • User + token are stored in localStorage
  • State is restored automatically when the user refreshes the page
  • No extra network calls are needed to reload the session
  • You can access auth from any component:
const { user, login, logout, getToken } = useAuth();

Plus, you get prebuilt UI screens:

  • <LoginScreen />
  • <SignupScreen />
  • <PasswordResetScreen />

And a simple <Protected> wrapper to guard pages.


📦 Installation

npm install @kendevelops/auth-flow-kit

or

bun add @kendevelops/auth-flow-kit

🚀 Usage (Next.js App Router)

Next.js layouts are server components, so we wrap the provider in a small client component.

1. Create app/AuthProviderClient.tsx

"use client";

import { AuthProvider } from "@kendevelops/auth-flow-kit";

export default function AuthProviderClient({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <AuthProvider
      config={{
        baseURL: "http://localhost:4000",
        endpoints: {
          login: "/auth/login",
          signup: "/auth/signup",
          forgot: "/auth/forgot",
        },
        onLoginSuccess: () => (window.location.href = "/dashboard"),
        onLogout: () => (window.location.href = "/login"),
      }}
    >
      {children}
    </AuthProvider>
  );
}

2. Wrap your app in app/layout.tsx

import AuthProviderClient from "./AuthProviderClient";
import "./globals.css";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <AuthProviderClient>{children}</AuthProviderClient>
      </body>
    </html>
  );
}

3. Login Page

"use client";
import { LoginScreen } from "@kendevelops/auth-flow-kit";

export default function LoginPage() {
  return <LoginScreen />;
}

4. Signup Page

"use client";
import { SignupScreen } from "@kendevelops/auth-flow-kit";

export default function SignupPage() {
  return <SignupScreen />;
}

5. Protected Dashboard Page

"use client";
import { Protected, useAuth } from "@kendevelops/auth-flow-kit";

export default function DashboardPage() {
  return (
    <Protected>
      <Dashboard />
    </Protected>
  );
}

function Dashboard() {
  const { user, logout } = useAuth();

  return (
    <div style={{ padding: 20 }}>
      <h1>Dashboard</h1>
      {user ? (
        <>
          <p>Logged in as {user.name}</p>
          <button onClick={logout}>Logout</button>
        </>
      ) : (
        <p>No user loaded.</p>
      )}
    </div>
  );
}

🧠 Developer Experience (DX)

Because auth behaves like a global store, you can access it anywhere:

const { user, login, logout, getToken, loading } = useAuth();

This means:

✔ Global state, just like Redux or Zustand

✔ No need for reducers, slices, or stores

✔ No extra setup

✔ No API calls on refresh — state is restored instantly

Your UI automatically updates when the user logs in, signs up, or logs out.


🔒 Protecting Routes and Components

<Protected>
  <SecretSection />
</Protected>

If the user is not authenticated, they are redirected to /login.


📄 Using useAuth() in any component

"use client";
import { useAuth } from "@kendevelops/auth-flow-kit";

export default function NavBar() {
  const { user, logout } = useAuth();

  return (
    <nav>
      {user ? (
        <>
          <span>Hi {user.name}</span>
          <button onClick={logout}>Logout</button>
        </>
      ) : (
        <a href="/login">Login</a>
      )}
    </nav>
  );
}

🌐 React (Non-Next.js) Usage

import { AuthProvider, LoginScreen } from "@kendevelops/auth-flow-kit";

export default function App() {
  return (
    <AuthProvider
      config={{
        baseURL: "http://localhost:4000",
        endpoints: {
          login: "/auth/login",
          signup: "/auth/signup",
          forgot: "/auth/forgot",
        },
      }}
    >
      <LoginScreen />
    </AuthProvider>
  );
}

🎉 Summary

auth-flow-kit provides:

  • Global auth state (Redux/Zustand style)
  • Prebuilt auth UI (Login, Signup, Reset)
  • Easy useAuth() hook access
  • Simple endpoint requirements
  • Works in both Next.js and React

A clean, modern solution for developers who want authentication without complexity.