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

@motherbase/ssr

v0.1.4

Published

Next.js SSR support for @motherbase/client — createBrowserClient, createServerClient, and a middleware session-refresh helper.

Readme

@motherbase/ssr

Next.js support for @motherbase/client: a browser client that persists the session to a cookie, a server client that reads it, and the middleware helper that refreshes it.

npm install @motherbase/client @motherbase/ssr

The three pieces, and why all three are required

A Next.js app needs the session in two runtimes: the browser, and the server that renders your Server Components. A cookie is the only thing both can see. Only one place is allowed to write it.

| Where | Use | Writes the cookie? | | --- | --- | --- | | Client Components | createBrowserClient | yes, via document.cookie | | Server Components, Route Handlers, Server Actions | createServerClient | no (Next.js forbids it in Server Components) | | proxy.ts / middleware.ts | updateSession | yes, this is the one that keeps it fresh |

Skipping updateSession is the single most common setup mistake, and it is silent: nothing throws, no Authorization header is ever attached, and auth.getUser() returns null on both sides. In development the SDK now warns on the console when it detects a session it could not write. In production it stays quiet, so set the middleware up.

Do not use createClient from @motherbase/client directly in a Next.js app: it stores the session in memory, which the server cannot read and a reload destroys.

Setup

// lib/client.ts  (Client Components)
import { createBrowserClient } from '@motherbase/ssr'

export function browserClient() {
  return createBrowserClient(
    process.env.NEXT_PUBLIC_MOTHERBASE_URL!,
    process.env.NEXT_PUBLIC_MOTHERBASE_KEY!,
  )
}
// lib/server.ts  (Server Components, Route Handlers, Server Actions)
import { cookies } from 'next/headers'
import { createServerClient } from '@motherbase/ssr'

export async function serverClient() {
  const store = await cookies()
  return createServerClient(
    process.env.NEXT_PUBLIC_MOTHERBASE_URL!,
    process.env.NEXT_PUBLIC_MOTHERBASE_KEY!,
    {
      cookies: {
        getAll: () => store.getAll(),
        setAll: (list) => {
          for (const { name, value, options } of list) store.set(name, value, options)
        },
      },
    },
  )
}
// proxy.ts on Next.js 16+, middleware.ts on Next.js 14 and 15.
// Same body either way; only the filename and the exported name differ.
import type { NextRequest } from 'next/server'
import { updateSession } from '@motherbase/ssr'

export async function proxy(request: NextRequest) {
  return updateSession(
    request,
    process.env.NEXT_PUBLIC_MOTHERBASE_URL!,
    process.env.NEXT_PUBLIC_MOTHERBASE_KEY!,
  )
}

export const config = {
  matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
}

updateSession never throws: if the backend is unreachable it leaves the existing cookie in place and the navigation proceeds.

Changing the cookie name

SESSION_COOKIE_KEY (motherbase.session) is the default. If you override it, override it in all three places, or the half that reads a name nobody writes will report the user as logged out:

createBrowserClient(url, key, { cookieKey: 'my-app.session' })
createServerClient(url, key, { cookies, cookieKey: 'my-app.session' })
updateSession(request, url, key, { cookieKey: 'my-app.session' })

Entry points

@motherbase/ssr is the main entry. The three modules are also addressable individually (@motherbase/ssr/browser, /server, /middleware) when you want to keep next/server out of a client bundle.

Compatibility

next >= 14, App Router. Types are checked against Next 15; the API used here (NextRequest, NextResponse, cookies()) is unchanged on Next 16, where the middleware.ts convention is deprecated in favour of proxy.ts.