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

gasket-plugin-auth

v0.2.0

Published

gasket plugin for oauth

Readme

gasket-plugin-auth

Add authentication to your Gasket apps in minutes using OpenAuth. Supports both modern Next.js App Router and Express applications.

Installation

npm install gasket-plugin-auth

Configuration

Add the plugin to your gasket.js:

import { makeGasket } from '@gasket/core';
import pluginAuth from 'gasket-plugin-auth';
import { createSubjects } from "@openauthjs/openauth";
import { object, string } from "valibot";

const subjects = createSubjects({
  user: object({
    id: string(),
  }),
});

export default makeGasket({
  plugins: [
    pluginAuth
  ],
  auth: {
    clientID: 'your-client-id',
    issuer: 'https://your-auth-server.com',
    subjects
  }
});

Usage with Next.js App Router

  1. Create API routes for auth flows:
// app/api/auth/login/route.ts
import { NextRequest } from 'next/server';
import gasket from '../../../../gasket';
import { loginHandler } from 'gasket-plugin-auth/api-routes';

const handler = (request: NextRequest) => loginHandler(gasket, request);
export { handler as GET };

// app/api/auth/callback/route.ts
import { NextRequest } from 'next/server';
import gasket from '../../../../gasket';
import { callbackHandler } from 'gasket-plugin-auth/api-routes';

const handler = (request: NextRequest) => callbackHandler(gasket, request);
export { handler as GET };
  1. Use in server components:
// app/protected/page.tsx
import gasket from '../../../gasket';
import { NextTokenStore } from 'gasket-plugin-auth/token-store/next';

export default async function ProtectedPage() {
  const store = new NextTokenStore();
  const verified = await gasket.actions.verifyAuthSession(store);
  
  if (!verified) {
    return <div>Not authenticated</div>;
  }

  return (
    <div>
      <h1>Protected Page</h1>
      <pre>{JSON.stringify(verified.subject, null, 2)}</pre>
    </div>
  );
}
  1. Add middleware for route protection:
// middleware.ts
export async function middleware(request: NextRequest) {
  if (url.pathname.includes('/protected')) {
    const res = await fetch(new URL('/api/auth/verify', url), {
      headers: {
        cookie: request.headers.get('cookie') || ''
      }
    });
    const { verified } = await res.json();
    if (!verified || verified.err) {
      return NextResponse.redirect(new URL('/api/auth/login', request.url));
    }
  }
  return NextResponse.next();
}
  1. Use the AuthProvider in your app:
// app/layout.tsx
import { AuthProvider } from 'gasket-plugin-auth/auth-context';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return <AuthProvider><div>{children}</div></AuthProvider>;
}
  1. Use the useAuth hook in your components:
// components/AuthButton.tsx
import { useAuth } from 'gasket-plugin-auth/hooks';

export function AuthButton() {
  const { isAuthenticated, isLoading, signIn, signOut } = useAuth();
  // ...
}

Usage with Express

  1. Use the auth middleware:
import { createAuthMiddleware } from 'gasket-plugin-auth/middleware';

app.use('/protected/*', createAuthMiddleware(gasket));
  1. Access auth in routes:
import { ExpressTokenStore } from 'gasket-plugin-auth/token-store/express';

app.get('/profile', async (req, res) => {
  const store = new ExpressTokenStore(req, res);
  const verified = await gasket.actions.verifyAuthSession(store);
  
  if (!verified) {
    return res.redirect('/login');
  }
  
  res.json({ user: verified.subject });
});

Available Actions

The plugin provides these Gasket actions:

  • verifyAuthSession(store) - Verify the current session
  • setAuthTokens(store, access, refresh) - Set auth tokens
  • getAuthTokens(store) - Get current tokens
  • clearAuthTokens(store) - Clear auth tokens

Features

  • 🔒 Secure authentication with OpenAuth
  • 🚂 Express middleware and Next.js API routes
  • 🛡️ Route protection
  • 🍪 Secure cookie-based sessions
  • 🔄 Automatic token refresh
  • 📦 Framework-agnostic token storage

Security

  • Tokens stored in HTTP-only cookies
  • CSRF protection via SameSite cookie attribute
  • Automatic token refresh
  • Secure cookie settings in production