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

@monocloud/auth-nextjs

v0.1.11

Published

MonoCloud Next.js Authentication SDK

Downloads

1,052

Readme

Introduction

MonoCloud Auth Next.js SDK – secure authentication and session management for Next.js applications.

MonoCloud is a modern, developer-friendly Identity & Access Management platform.

This SDK is designed specifically for Next.js, providing first-class integration with both the App Router and Pages Router. It leverages Next.js Middleware, Server Components, and Edge-compatible APIs to deliver secure, server-side authentication with minimal configuration.

📘 Documentation

Supported Platforms

  • Next.js ≥ 13.0.0 (App Router & Pages Router)
  • Node.js ≥ 16.0.0
  • Edge Runtime (where supported by Next.js)

🚀 Getting Started

Requirements

  • A MonoCloud Tenant
  • A Client ID and Client Secret
  • A Random secret (32+ characters) for encrypting session cookies

📦 Installation

npm install @monocloud/auth-nextjs

Initialization

Set up environment variables

Create a .env.local file in your project root. The SDK automatically reads variables prefixed with MONOCLOUD_AUTH__.

MONOCLOUD_AUTH_TENANT_DOMAIN=https://<your-tenant-domain>
MONOCLOUD_AUTH_CLIENT_ID=<your-client-id>
MONOCLOUD_AUTH_CLIENT_SECRET=<your-client-secret>
MONOCLOUD_AUTH_COOKIE_SECRET=<long-random-string>
MONOCLOUD_AUTH_APP_URL=http://localhost:3000

Generate a secure cookie secret:

openssl rand -hex 32

⚠️ Security Note: Never commit secrets to source control. Always load them from environment variables.

Create Next Client

Create a shared MonoCloud client instance (for example, lib/monocloud.ts) and reuse it throughout your application.

import { MonoCloudNextClient } from '@monocloud/auth-nextjs';

// Environment variables are picked up automatically
export const monoCloud = new MonoCloudNextClient();

⚠️ Security Note: Never commit your credentials to version control. Load them from environment variables.

Add MonoCloud Middleware

Protect your application by registering the MonoCloud middleware. Authentication routes, redirects, and callbacks are handled automatically.

‼️ Important (Next.js v16+): Starting with Next.js 16, authentication middleware is implemented using a proxy-based approach rather than traditional middleware files. MonoCloud follows this recommended proxy pattern for handling authentication flows.

import { monoCloud } from '<shared-instance>';

export default monoCloud.authMiddleware();

// Allow static files
export const config = {
  matcher: ['/((?!.+\\.[\\w]+$|_next).*)', '/', '/(api|trpc)(.*)'],
};

Get Session (Server-side)

Retrieve the authenticated session in Server Components, Route Handlers, or API routes.

import { monoCloud } from '<shared-instance>';

export default async function Page() {
  const session = await monoCloud.getSession();

  return (
    <div>
      <h1>Welcome, {session?.user?.name}</h1>
      <p>Email: {session?.user?.email}</p>
    </div>
  );
}

Get User (Client-side)

Access user data in Client Components using the provided hook.

'use client';

import { useAuth } from '@monocloud/auth-nextjs/client';

export default function Page() {
  const { user } = useAuth();

  return (
    <div>
      <h1>Welcome, {user?.name}</h1>
      <p>Email: {user?.email}</p>
    </div>
  );
}

When should I use auth-nextjs?

Use @monocloud/auth-nextjs if you are building a Next.js application and want a secure authentication solution with minimal configuration.

This package is a good fit if you:

  • Are using Next.js (App Router or Pages Router)
  • Want secure, cookie-based sessions managed for you
  • Need authentication in Server Components, Route Handlers, API routes, and middleware/proxy
  • Prefer framework-native helpers and React hooks
  • Want an opinionated, batteries-included authentication experience

🤝 Contributing & Support

Issues & Feedback

  • Use GitHub Issues for bug reports and feature requests.
  • For tenant or account-specific help, contact MonoCloud Support through your dashboard.

Security

Do not report security issues publicly. Please follow the contact instructions at: https://www.monocloud.com/contact

📄 License

Licensed under the MIT License. See the included LICENSE file.