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

@econneq/auth-nextjs

v1.0.10

Published

Next.js App Router integration — middleware, server actions, SSR auth

Readme

@econneq/auth-nextjs

Next.js App Router integration — middleware that gates routes and server utilities that read tokens inside Server Components, Server Actions, and Route Handlers.

Position in the install order

1. auth-core    ◄── prerequisite
2. auth-nextjs  ◄── you are here  (parallel with auth-react)
   auth-react   ◄── needed in your app for client-side hooks/guards

Install @econneq/auth-core first. This package only depends on auth-core directly, but in practice your app will also pull in @econneq/auth-react (for <AuthProvider> + hooks) and optionally @econneq/auth-ui (for the login/tenant pages).

Install

npm install @econneq/auth-core @econneq/auth-nextjs
# and, in the app:
npm install @econneq/auth-react   # client side

Peer deps: next >=14, react >=18, react-dom >=18.

Three entry points

import { defineAuthConfig }     from '@econneq/auth-nextjs'             // root
import { createAuthMiddleware } from '@econneq/auth-nextjs/middleware'  // edge
import { getServerUser, serverCan, getServerAuthHeader }
                                from '@econneq/auth-nextjs/server'      // RSC / actions

Keep the imports separated — the middleware bundle runs at the edge and must not pull in Node-only code, which is why /server is a different subpath.

Wire the middleware

// proxy.ts (or middleware.ts)
import { createAuthMiddleware } from '@econneq/auth-nextjs/middleware'
import { authConfig }           from './src/auth/auth.config'

export default createAuthMiddleware(authConfig, {
  protectedRoutes: ['/dashboard', '/app'],
  publicRoutes:    ['/auth/login', '/auth/register', '/auth/mfa'],
  loginUrl:        '/auth/login',
  tenantSelectUrl: '/auth/select-tenant',
})

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

What it does:

  • No global token → redirect to loginUrl (with ?next=).
  • Token expired → same redirect.
  • Global token present but no tenant token (when tenantMode) → redirect to tenantSelectUrl.
  • Authenticated → forwards the request and injects x-auth-user-id, x-auth-tenant-key, x-auth-roles headers for downstream Server Components.

Read auth in Server Components / Actions

import { getServerUser, serverCan, getServerAuthHeader }
  from '@econneq/auth-nextjs/server'

export default async function DashboardPage() {
  const { token, userId } = await getServerUser()       // redirects if missing
  const canExport         = await serverCan('reports.export')
  return <Header name={token.fullName} canExport={canExport} />
}

// In a Server Action calling your GraphQL/REST API:
const auth = await getServerAuthHeader()
fetch(API, { headers: { Authorization: auth } })

Also available: getGlobalToken(), getTenantToken(), getServerRoles().

Build

npm run build      # tsup → dist with /middleware and /server subpaths
npm run typecheck
npm run dev

Notes

  • Cookie names are fixed: ea_global_token and ea_tenant_token. They must be set HttpOnly by your auth API.
  • The /server module imports next/headers and next/navigation — only call it from server contexts.
  • For client-side hooks and guards, use @econneq/auth-react — this package deliberately doesn't re-export them.