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 πŸ™

Β© 2025 – Pkg Stats / Ryan Hefner

nuxt-betterauth-cf

v1.0.23

Published

Nuxt, Better Auth and Cloudflare πŸ”₯

Readme

Nuxt, Better Auth and Cloudflare D1

Add Better Auth to you Nuxt project powered by Cloudflare with ease.

Features

  • β›° Β Easy setup, minimal configuration
  • 🚠 Β Integrates D1 and KV
  • 🌲 Β Manage schemas Drizzle

Quick Setup

Install the module to your Nuxt application with one command:

npx nuxi module add nuxt-betterauth-cf

Install the dependencies in your project.

pnpm add -D drizzle-kit wrangler @cloudflare/workers-types
pnpm add drizzle-kit better-auth

Add this to your package.json file

{
  // ...
  "scripts": {
    // ...
    "db:generate": "pnpm drizzle-kit generate",
    "db:migrate": "wrangler d1 migrations apply <your app name> --local",
    "auth:generate": "pnpx @better-auth/cli generate --output ./db/schemas/auth.ts"
  }
}

Create a wrangler.jsonc or wranger.toml file in the root of your project: https://developers.cloudflare.com/workers/wrangler/configuration/

The module automatically creates these files in your project:

.
β”œβ”€β”€ auth
β”‚   └── config.ts
β”œβ”€β”€ db
β”‚   └── schemas
β”‚       β”œβ”€β”€ app.ts
β”‚       β”œβ”€β”€ auth.ts
β”‚       └── index.ts
β”œβ”€β”€ drizzle.config.ts
└── lib
    └── auth.ts

Configuration

The module is somewhat opinionated in terms of how Cloudflare D1 and Cloudflare KV is integrated. To setup modules, hooks etc. for Better Auth, go to the auth/config.ts file.

From here you can centrally manage your server- and client side configuration.

It's important that the file exports a config and client.

import { defineAuthConfig, defineAuthClientConfig } from 'nuxt-betterauth-cf/config'
import { username } from "better-auth/plugins"
import { usernameClient } from "better-auth/client/plugins"

export const config = defineAuthConfig({
  plugins: [username()]
})

export const client = defineAuthClientConfig({
  plugins: [usernameClient()]
})

Composables

This module comes with a useAuth composable for easy interaction with Better Auth. Please infer the return type to see the different helpers provided by the composable. You can always access the raw Better Auth client through .client.

<script setup lang="ts">
  const auth = useAuth()

  const client = auth.client // Maps to the raw Better Auth client
</script>

Server routes

This module automatically adds the api endpoint required by Better Auth. If you want to setup protected routes you can use the defineAuthenticatedEventHandler.

It's auto-imported for you and works the same as defineEventHandler with the difference that it checks for a valid Better Auth session or throws and error.

The current session and Better Auth instance is provided through the event.context.

export default defineAuthenticatedEventHandler(async (event) => {
  const session = event.context.session // The current session
  const auth = event.context.auth // The Better Auth instance
})

Credits

Inspired by atinux/nuxthub-better-auth