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

@siteai/auth-astro

v0.2.0

Published

Astro shell helpers and prebuilt `.astro` components for SiteAI customer sites.

Downloads

618

Readme

@siteai/auth-astro

Astro shell helpers and prebuilt .astro components for SiteAI customer sites.

The intended architecture is:

  • Astro owns the page shell, routing, and static markup.
  • @siteai/auth-react owns authenticated behavior and UI inside hydrated islands.
  • Auth-gated pages should prefer client-side protection (ProtectedPage.astro or composite *Island components), not server-side redirects or per-request auth middleware.

Compatible with Astro 4.x and 5.x.

Install

npm install @siteai/auth-astro

Wiring the integration

Add siteaiAuth() to your astro.config.mjs integrations array. This ensures @siteai/auth-react and @siteai/auth-core are pre-bundled correctly by Vite.

// astro.config.mjs
import { defineConfig } from 'astro/config';
import react from '@astrojs/react';
import { siteaiAuth } from '@siteai/auth-astro/integration';

export default defineConfig({
  integrations: [react(), siteaiAuth()],
});

Preferred pattern

For customer SiteAI sites, treat auth pages and member-only pages as Astro shell + client island/app surface.

  • Public pages can stay plain Astro.
  • Login / signup / account pages should mount composite islands from @siteai/auth-react.
  • Simple protected pages should wrap their content in ProtectedPage.astro.
---
import ProtectedPage from '@siteai/auth-astro/ProtectedPage.astro';

const apiUrl = import.meta.env.PUBLIC_SITEAI_API_URL;
const siteId = import.meta.env.PUBLIC_SITEAI_SITE_ID;
---

<ProtectedPage apiUrl={apiUrl} siteId={siteId}>
  <main class="mx-auto max-w-4xl px-4 py-10">
    <h1>My Account</h1>
    <p>This Astro page shell stays static-friendly; auth checking happens in the client island.</p>
  </main>
</ProtectedPage>

AuthIsland.astro renders a client-side auth UI island (login / user menu). ProtectedPage.astro wraps a page and redirects unauthenticated visitors after hydration.

Legacy helpers

createAuthMiddleware and protectedRoute are still exported for compatibility, but they are deprecated as the default pattern on Cloudflare Pages because they recreate server-side first-paint auth checks.

Use them only when you are maintaining an existing site that already depends on them and you are not yet ready to migrate that route to ProtectedPage.astro or a composite @siteai/auth-react island.

Deprecated middleware example

Wire session propagation in src/middleware.ts. The middleware runs on the server, so use non-prefixed env vars — the PUBLIC_ prefix would leak the values to the browser bundle.

import { createAuthMiddleware } from '@siteai/auth-astro';

export const onRequest = createAuthMiddleware({
  apiUrl: import.meta.env.SITEAI_API_URL,
  siteId: import.meta.env.SITEAI_SITE_ID,
});

Deprecated guarded-page example:

import { protectedRoute } from '@siteai/auth-astro';

Prebuilt components

Import the .astro island components via their subpath exports. Pass apiUrl and siteId as props — these values reach the client bundle at hydration, so source them from PUBLIC_-prefixed env vars.

---
import AuthIsland from '@siteai/auth-astro/AuthIsland.astro';
import ProtectedPage from '@siteai/auth-astro/ProtectedPage.astro';

const apiUrl = import.meta.env.PUBLIC_SITEAI_API_URL;
const siteId = import.meta.env.PUBLIC_SITEAI_SITE_ID;
---

<AuthIsland apiUrl={apiUrl} siteId={siteId}>
  <slot />
</AuthIsland>

<ProtectedPage apiUrl={apiUrl} siteId={siteId} />

Environment variables

Typical setups define two pairs of variables pointing at the same underlying values:

  • Server-side (middleware): SITEAI_API_URL, SITEAI_SITE_ID. Set in .env; never PUBLIC_-prefixed.
  • Client-side (island components need the values at hydration): PUBLIC_SITEAI_API_URL, PUBLIC_SITEAI_SITE_ID. The PUBLIC_ prefix is how Astro/Vite exposes env vars to the browser.

Contract

Emitted by the SiteAI Auth Builder curated skill on VibeControl. The builder now emits client-side protected pages and composite auth islands by default; it should not teach createAuthMiddleware / protectedRoute(Astro) as the primary setup path.

License

MIT © BUILD3R Dev