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

@supatype/ssr

v0.1.13

Published

Supatype server-side rendering utilities, create a client from cookie-based auth for Server Components, Route Handlers, and middleware

Readme

@supatype/ssr

Server-side rendering utilities for Supatype. Creates a typed client from cookie-based auth context so Server Components, Route Handlers, and middleware can access the current user's session without any browser APIs.

Installation

pnpm add @supatype/ssr

Usage

Next.js App Router

Create a server client factory that reads cookies on each request:

// lib/supatype-server.ts
import { createServerClient } from "@supatype/ssr"
import { cookies } from "next/headers"
import type { Database } from "@/types/database"

const url = process.env.NEXT_PUBLIC_SUPATYPE_URL!
const anonKey = process.env.NEXT_PUBLIC_SUPATYPE_ANON_KEY!

export async function createClient() {
  const cookieStore = await cookies()
  return createServerClient<Database>(url, anonKey, {
    cookies: {
      getAll() { return cookieStore.getAll() },
      setAll(cookiesToSet) {
        try {
          cookiesToSet.forEach(({ name, value, options }) =>
            cookieStore.set(name, value, options ?? {})
          )
        } catch { /* no-op in read-only Server Component context */ }
      },
    },
  })
}

Use it in a Server Component:

// app/page.tsx
import { createClient } from "@/lib/supatype-server"

export default async function Page() {
  const supatype = await createClient()
  const { data: posts } = await supatype.from("posts").select().eq("status", "published")
  // ...
}

Access the session in a Server Component or Route Handler:

const supatype = await createClient()
const { data: { session } } = await supatype.auth.getSession()
// session is null if no valid cookie is present

Cookie adapter interface

createServerClient accepts any framework's cookie store via the CookieAdapter interface:

interface CookieAdapter {
  getAll(): Array<{ name: string; value: string }>
  setAll(cookies: Array<{ name: string; value: string; options?: CookieOptions }>): void
}

Cookie prefix

Auth tokens are stored under st-<project-ref>-auth-token by default. If you've configured a custom prefix, pass it via cookiePrefix:

createServerClient(url, anonKey, {
  cookies: adapter,
  cookiePrefix: "myapp",
})

How it works

  1. Reads all cookies via the adapter's getAll()
  2. Finds the auth token cookie matching <prefix>-*-auth-token
  3. Parses the JSON session value and checks the JWT exp claim, expired tokens are discarded
  4. Passes the session as initialSession to createClient, so all subsequent requests carry the user's JWT automatically
  5. Signature verification is handled server-side by the gateway when the token is forwarded

API

createServerClient<TDatabase>(url, anonKey, options)

Returns a fully-typed SupatypeClient pre-loaded with the user's session from cookies. The returned client has the same API as the browser client, .from(), .auth, .storage, .rpc(), etc.

| Option | Type | Default | Description | |--------|------|---------|-------------| | cookies | CookieAdapter | required | Read/write cookie adapter | | cookiePrefix | string | "st" | Cookie name prefix |