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

@myauth/next

v1.4.0

Published

Next.js SDK for MyAuth authentication service

Downloads

340

Readme

@myauth/next

Next.js SDK for MyAuth authentication service

Installation

npm install @myauth/next

Usage

Middleware Protection

Protect your routes using the middleware:

// middleware.ts
import { withAuthMiddleware } from "@myauth/next";

export default withAuthMiddleware("your-client-id");

Server-Side Authentication

Get the current session on the server:

import { auth } from "@myauth/next";

export default async function ProtectedPage() {
  const session = await auth();

  if (!session) {
    return <div>Please log in</div>;
  }

  return <div>Welcome, {session.user.email}!</div>;
}

Getting Current User

Get the current user directly:

import { currentUser } from "@myauth/next";

export default async function UserProfile() {
  const user = await currentUser();

  if (!user) {
    return <div>Please log in</div>;
  }

  return <div>Welcome, {user.email}!</div>;
}

Client-Side Authentication

Wrap your app with the AuthProvider and use the useAuth hook:

// app/layout.tsx
import { AuthProvider } from "@myauth/next";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <AuthProvider>{children}</AuthProvider>
      </body>
    </html>
  );
}

// components/MyComponent.tsx
import { useAuth } from "@myauth/next";

export function MyComponent() {
  const { user, login, logout, loading } = useAuth();

  if (loading) return <div>Loading...</div>;

  return (
    <div>
      {user ? (
        <div>
          <p>Welcome, {user.email}!</p>
          <button onClick={logout}>Logout</button>
        </div>
      ) : (
        <button onClick={login}>Login</button>
      )}
    </div>
  );
}

Using the useUser Hook

Access the current user and loading state with a simpler hook:

import { useUser } from "@myauth/next";

export function UserDisplay() {
  const { user, loading } = useUser();

  if (loading) return <div>Loading...</div>;

  return (
    <div>
      {user ? <p>Current user: {user.email}</p> : <p>No user logged in</p>}
    </div>
  );
}

Authentication Callback Handler

Handle authentication callbacks in your API routes:

// app/api/auth/callback/route.ts
import { createAuthCallbackHandler } from "@myauth/next";

export const GET = createAuthCallbackHandler({
  successRedirect: "/",
  failureRedirect: "/login",
});

Authentication with Redirect Callback Component

For pages that handle redirects:

// app/auth/callback/page.tsx
import { AuthenticateWithRedirectCallback } from "@myauth/next";

export default function AuthCallbackPage() {
  return <AuthenticateWithRedirectCallback />;
}

API Reference

Server Functions

  • auth() - Returns the current session or null
  • currentUser() - Returns the current user or null
  • createAuthCallbackHandler(options) - Creates a handler for auth callbacks
  • getSessionToken() - Gets the session token

Client Components

  • AuthProvider - React context provider for authentication
  • useAuth() - Hook to access authentication state and methods
  • useUser() - Hook to access the current user and loading state
  • AuthenticateWithRedirectCallback - Component for handling auth redirects

Middleware

  • withAuthMiddleware(clientId) - Creates middleware to protect routes

Types

type User = {
  email: string;
};

type AuthState = {
  user: User | null;
  token: string | null;
  loading: boolean;
  logout: () => Promise<void>;
  login: () => Promise<void>;
};

type Session = {
  user: User | null;
  token: string | null;
};

License

ISC packages/next-sdk/README.md