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

stargate-better-auth

v0.1.0

Published

Better Auth plugin for GitHub star-gated access control

Readme

⭐ Stargate for Better Auth

CI npm version License: MIT

Gate access to Better Auth resources based on whether the user has starred a repository. ⭐

Installation

npm install stargate-better-auth
# or
bun add stargate-better-auth
# or
pnpm add stargate-better-auth

Requirements

  • Better Auth ^1.2.0
  • GitHub OAuth configured in Better Auth

Quick Start

Server

import { betterAuth } from "better-auth";
import { githubStarGate } from "stargate-better-auth";

export const auth = betterAuth({
  socialProviders: {
    github: {
      clientId: process.env.GITHUB_CLIENT_ID,
      clientSecret: process.env.GITHUB_CLIENT_SECRET,
    },
  },
  plugins: [
    githubStarGate({
      repository: "owner/repo",
    }),
  ],
});

Client

import { createAuthClient } from "better-auth/client";
import { githubStarGateClient } from "stargate-better-auth/client";

const client = createAuthClient({
  plugins: [githubStarGateClient()],
});

// Check status
const { hasStarred } = await client.starGate.checkStarStatus();

// Force refresh
await client.starGate.refreshStarStatus();

Configuration

githubStarGate({
  // Required: repository to check
  repository: "owner/repo",

  // Cache duration in minutes (default: 15)
  cacheDuration: 15,

  // What to do when GitHub API fails (default: "allow")
  onApiFailure: "allow" | "deny",

  // Grace period when user un-stars (default: immediate revocation)
  gracePeriod: {
    strategy: "immediate" | "timed" | "never",
    duration: 3600, // seconds, for "timed" strategy
  },

  // Debug logging (default: false)
  enableLogging: false,

  // Custom error messages
  customErrorMessages: {
    notStarred: "Please star our repo to continue.",
  },
})

API Endpoints

GET /api/auth/star-gate/status

Returns current star status.

{
  "hasStarred": true,
  "repository": "owner/repo",
  "lastChecked": "2025-01-15T10:30:00Z",
  "cacheExpires": "2025-01-15T10:45:00Z",
  "gracePeriodActive": false
}

POST /api/auth/star-gate/refresh

Force refresh from GitHub API (rate limited: 5/min).

{
  "hasStarred": true,
  "repository": "owner/repo",
  "refreshedAt": "2025-01-15T10:35:00Z"
}

Grace Period Strategies

| Strategy | Behavior | |----------|----------| | immediate | Revoke access immediately when star is removed | | timed | Allow continued access for duration seconds after un-star | | never | Never revoke once granted (until session expires) |

Error Codes

| Code | Description | |------|-------------| | STAR_REQUIRED | User hasn't starred the repository | | GITHUB_ACCOUNT_NOT_FOUND | No GitHub account linked | | GITHUB_TOKEN_MISSING | GitHub token unavailable | | TOKEN_EXPIRED | GitHub token expired, re-auth required | | API_FAILURE | GitHub API unavailable |

Database Schema

The plugin adds a starVerification table:

| Column | Type | Description | |--------|------|-------------| | userId | string | Foreign key to user | | repository | string | Repository being verified | | hasStarred | boolean | Current star status | | lastCheckedAt | datetime | Last verification time | | expiresAt | datetime | Cache expiration |

Session fields added: hasStarAccess, starVerifiedAt, gracePeriodActive.

Rate Limits

  • /star-gate/status: 30 requests/minute
  • /star-gate/refresh: 5 requests/minute

GitHub API: 5000 requests/hour per token. With 15-minute caching, supports ~333 users/minute.

Troubleshooting

"GITHUB_ACCOUNT_NOT_FOUND"

User signed in with a different provider. They need to link their GitHub account or sign in with GitHub.

"TOKEN_EXPIRED"

The stored GitHub OAuth token has expired. User needs to re-authenticate with GitHub.

API rate limiting

If you're hitting GitHub's rate limits:

  1. Increase cacheDuration (e.g., 30 or 60 minutes)
  2. Set onApiFailure: "allow" to gracefully degrade

Contributing

git clone https://github.com/neiii/stargate-better-auth
cd stargate-better-auth
bun install
bun test

License

MIT © d0