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

authme-nextjs

v1.0.1

Published

Next.js SDK for AuthMe Identity and Access Management Server

Readme

authme-nextjs

Next.js SDK for AuthMe — integrates AuthMe OIDC authentication into Next.js applications with support for the App Router, Pages Router, middleware, and Server Components.

Installation

npm install authme-nextjs authme-sdk

Quick Start

1. Wrap your app with AuthProvider

// app/layout.tsx
'use client';
import { AuthProvider } from 'authme-nextjs';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html>
      <body>
        <AuthProvider
          serverUrl="http://localhost:3000"
          realm="my-realm"
          clientId="my-app"
          redirectUri="http://localhost:3001/callback"
        >
          {children}
        </AuthProvider>
      </body>
    </html>
  );
}

2. Use auth state in client components

'use client';
import { useAuth } from 'authme-nextjs';

export function NavBar() {
  const { isAuthenticated, user, login, logout, isLoading } = useAuth();

  if (isLoading) return <span>Loading...</span>;
  if (!isAuthenticated) return <button onClick={() => login()}>Sign In</button>;
  return (
    <div>
      <span>{user?.name}</span>
      <button onClick={logout}>Sign Out</button>
    </div>
  );
}

3. Protect routes with middleware

// middleware.ts
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { createAuthMiddleware } from 'authme-nextjs/middleware';

const authMiddleware = createAuthMiddleware({
  serverUrl: 'http://localhost:3000',
  realm: 'my-realm',
  clientId: 'my-app',
  protectedPaths: ['/dashboard', '/api/protected'],
  loginPath: '/login',
});

export default function middleware(request: NextRequest) {
  return authMiddleware(request as never, NextResponse as never);
}

export const config = {
  matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};

4. Server Components

// app/dashboard/page.tsx
import { cookies } from 'next/headers';
import { getServerUser } from 'authme-nextjs/server';
import { redirect } from 'next/navigation';

export default async function DashboardPage() {
  const cookieStore = cookies();
  const user = await getServerUser(cookieStore, {
    serverUrl: 'http://localhost:3000',
    realm: 'my-realm',
  });

  if (!user) redirect('/login');

  return <h1>Hello, {user.name}!</h1>;
}

5. API Routes (Pages Router)

// pages/api/profile.ts
import { withAuth } from 'authme-nextjs/api';

export default withAuth(
  { serverUrl: 'http://localhost:3000', realm: 'my-realm' },
  (req, res) => {
    res.json({ user: req.authUser });
  },
);

5b. Route Handlers (App Router)

// app/api/profile/route.ts
import { withAuthHandler } from 'authme-nextjs/api';

export const GET = withAuthHandler(
  { serverUrl: 'http://localhost:3000', realm: 'my-realm' },
  (_req, user) => Response.json({ user }),
);

API Reference

authme-nextjs (default export)

Re-exports from authme-sdk/react:

  • AuthProvider / AuthmeProvider — context provider
  • useAuth() — authentication state and actions
  • useUser() — current user info
  • usePermissions() — role and permission helpers
  • ProtectedRoute — render-gate component
  • AuthmeClient — raw client class

authme-nextjs/middleware

  • createAuthMiddleware(config) — Next.js Edge middleware factory

authme-nextjs/server

  • getServerAuth(cookies, config?) — returns AuthSession | null
  • getServerUser(cookies, config?) — returns User | null

authme-nextjs/api

  • withAuth(config, handler) — Pages Router API handler wrapper
  • withAuthHandler(config, handler) — App Router Route Handler wrapper

License

MIT