Socket
Book a DemoInstallSign in
Socket

nuxt-betterauth-cf

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuxt-betterauth-cf

Nuxt, Better Auth and Cloudflare πŸ”₯

1.0.17
latest
Source
npmnpm
Version published
Weekly downloads
424
107.84%
Maintainers
1
Weekly downloads
Β 
Created
Source

Nuxt, Better Auth and Cloudflare D1

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

  • ✨ Β Release Notes

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

FAQs

Package last updated on 01 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.