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

oneauth-nextjs

v1.0.7

Published

Next.js integration for OneAuth SDK with middleware and SSR support

Downloads

5

Readme

OneAuth Next.js SDK

Add secure authentication to your Next.js app in minutes with just a few lines of code.

Quick Start

Get authentication working in your Next.js app with 3 simple steps:

1. Install

npm install oneauth-nextjs

2. Wrap your app

// app/layout.tsx
import { AuthProvider } from 'oneauth-nextjs'

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <AuthProvider config={{ 
          apiUrl: 'http://localhost:8080',
          authMode: 'password',
          providers: ['google', 'github']
        }}>
          {children}
        </AuthProvider>
      </body>
    </html>
  )
}

3. Add authentication to any page

// app/page.tsx
'use client'
import { SignedIn, SignedOut, SignInButton, UserButton } from 'oneauth-nextjs'

export default function Home() {
  return (
    <>
      <header style={{ display: 'flex', justifyContent: 'space-between', padding: '1rem' }}>
        <h1>My App</h1>
        <SignedOut>
          <SignInButton />  
        </SignedOut>
        <SignedIn>
          <UserButton />
        </SignedIn>
      </header>
      
      <main style={{ padding: '2rem', textAlign: 'center' }}>
        <SignedOut>
          <h2>Welcome! Please sign in to continue</h2>
        </SignedOut>
        
        <SignedIn>
          <h2>🎉 You're signed in!</h2>
        </SignedIn>
      </main>
    </>
  )
}

That's it! Your Next.js app now has:

  • ✅ Google & GitHub OAuth
  • ✅ Email/password authentication
  • ✅ User sessions
  • ✅ Sign in/out components
  • ✅ Automatic user management

Features

  • 🚀 Next.js 13+ App Router - Full support for the latest Next.js App Router
  • 📄 Pages Router Compatible - Works with traditional Pages Router setup
  • 🔒 Secure by Default - Built-in security best practices
  • 🎨 Ready-to-use Components - Drop-in authentication UI
  • 🌐 OAuth Providers - GitHub, Google, and more
  • TypeScript Ready - Full TypeScript support

Pages Router Setup

For Next.js Pages Router, wrap your app in _app.tsx:

// pages/_app.tsx
import { AuthProvider } from 'oneauth-nextjs'

export default function App({ Component, pageProps }) {
  return (
    <AuthProvider config={{ 
      apiUrl: 'http://localhost:8080',
      authMode: 'password',
      providers: ['google', 'github']
    }}>
      <Component {...pageProps} />
    </AuthProvider>
  )
}

Then use the same components in any page:

// pages/index.tsx
import { SignedIn, SignedOut, SignInButton, UserButton } from 'oneauth-nextjs'

export default function Home() {
  return (
    <div>
      <SignedOut>
        <SignInButton />
      </SignedOut>
      <SignedIn>
        <UserButton />
      </SignedIn>
    </div>
  )
}

Get User Information

Access user data anywhere with the useAuth hook:

import { useAuth } from 'oneauth-nextjs'

function MyComponent() {
  const { user, isAuthenticated } = useAuth()

  if (!isAuthenticated) {
    return <div>Please sign in</div>
  }

  return (
    <div>
      <h2>Welcome {user.fullName}!</h2>
      <p>Email: {user.email}</p>
      <p>Provider: {user.registeredProviderName}</p>
    </div>
  )
}

Available Components

| Component | Description | |-----------|-------------| | <SignInButton /> | Shows sign in button when user is signed out | | <UserButton /> | Shows user avatar and menu when signed in | | <SignedIn> | Only shows children when user is signed in | | <SignedOut> | Only shows children when user is signed out | | <AuthModal /> | Full authentication modal |

Configuration Options

<AuthProvider config={{
  apiUrl: 'http://localhost:8080',          // Your OneAuth server
  authMode: 'password',                     // 'password' | 'passwordless' | 'oauth'
  providers: ['google', 'github'],         // OAuth providers
  enableVerificationInput: false,           // Require email verification
  alwaysFetchUser: false,                   // Always fetch user on load
  advanced: {
    debug: false                            // Enable debug mode
  }
}}>

Custom Authentication Modal

Use AuthModal for a custom sign-in experience:

import { AuthModal, useAuth } from 'oneauth-nextjs'

function MyApp() {
  const { isModalOpen, hideModal } = useAuth()
  
  return (
    <>
      <SignInButton />
      
      <AuthModal 
        isOpen={isModalOpen} 
        onClose={hideModal}
        onSuccess={hideModal}
        appName="My App"
      />
    </>
  )
}

Environment Variables

Set up your environment variables:

# .env.local
ONE_AUTH_SERVER_URL=http://localhost:8080

Then use in your config:

<AuthProvider config={{ 
  apiUrl: process.env.ONE_AUTH_SERVER_URL || 'http://localhost:8080',
  // ... other config
}}>

TypeScript Support

Full TypeScript support out of the box:

import { useAuth, User } from 'oneauth-nextjs'

function UserProfile() {
  const { user, isAuthenticated }: {
    user: User | null
    isAuthenticated: boolean
  } = useAuth()

  return (
    <div>
      {user?.fullName && <h2>{user.fullName}</h2>}
      <p>{user?.email}</p>
    </div>
  )
}

Examples

Check out complete examples:

Need Help?


Made with ❤️ by the OneAuth team