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

nica-next

v0.6.0

Published

Next.js adapter for nica — session management and React hooks

Readme

nica-next

Next.js adapter for nica — session management, cookie handling, and React hooks.

Installation

npm install nica-next

Usage

import nica from "nica-next";

const auth = nica({
  providers: {
    github: {
      clientId: process.env.GITHUB_CLIENT_ID!,
      clientSecret: process.env.GITHUB_CLIENT_SECRET!,
      redirectUri: "https://myapp.com/api/auth/github/callback",
    },
  },
  session: {
    secret: process.env.SESSION_SECRET!,
  },
  onProfile: async ({ profile }) => {
    // Save user to DB, return data to store in session
    const user = await db.upsertUser(profile);
    return { userId: user.id };
  },
});

Redirect routeapp/api/auth/[provider]/route.ts:

export async function GET(_req: Request, { params }: { params: Promise<{ provider: string }> }) {
  const { provider } = await params;
  return auth.redirect(provider);
}

Callback routeapp/api/auth/[provider]/callback/route.ts:

import { NextRequest, NextResponse } from "next/server";

export async function GET(req: NextRequest, { params }: { params: Promise<{ provider: string }> }) {
  const { provider } = await params;
  const { response } = await auth.callback(req, provider);
  return NextResponse.redirect(new URL("/dashboard", req.url), { headers: response.headers });
}

Read session in a Server Component:

const session = await auth.session.get();
if (!session) redirect("/login");

React session — setup (once in your auth config):

// lib/auth.ts
import nica from "nica-next";

export const auth = nica({ ... });
export const { SessionProvider, useSession } = auth;

Wrap your root layout with SessionProviderapp/layout.tsx:

import { SessionProvider } from "@/lib/auth";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html>
      <body>
        <SessionProvider>{children}</SessionProvider>
      </body>
    </html>
  );
}

Use useSession in any Client Component:

"use client";

import { useSession } from "@/lib/auth";

export function Profile() {
  const { session } = useSession();
  if (!session) return <p>Not authenticated</p>;
  return <p>Welcome {session.userId}</p>;
}

Destroy session (logout):

const res = NextResponse.redirect(new URL("/", req.url));
await auth.session.destroy({ response: res });
return res;

Session Configuration

session: {
  secret: string;                  // required, min 32 chars
  strategy?: "encrypted" | "signed"; // default: "encrypted" (AES-GCM)
  tokenExp?: number;               // default: 7 days (seconds)
  cookie?: {
    name?: string;                 // default: "nica_session"
    maxAge?: number;               // default: 7 days (seconds)
    httpOnly?: boolean;            // default: true
    secure?: boolean;              // default: true
    sameSite?: "lax" | "strict" | "none"; // default: "lax"
    path?: string;                 // default: "/"
  },
}

Providers

Supports all providers from nica: google · github · facebook · linkedin · slack · twitter · microsoft · twitch · discord

Custom providers are also supported — see nica docs.

Error Handling

redirect() and callback() throw NicaError on failure. Additional error codes specific to nica-next:

| Code | When thrown | |------|-------------| | PKCE_COOKIE_MISSING | callback() called but the PKCE cookie is absent or expired | | INVALID_STATE | PKCE cookie signature invalid, or state mismatch between redirect and callback |

License

MIT