Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<p align="center">
<img src="https://raw.githubusercontent.com/onmax/nuxt-better-auth/main/.github/og.png" alt="Nuxt Better Auth" width="100%">
<img src="https://raw.githubusercontent.com/nuxt-modules/better-auth/main/.github/og.png" alt="Nuxt Better Auth" width="100%">
<br>
<sub>Designed by <a href="https://github.com/HugoRCD">HugoRCD</a></sub>
</p>

<h1 align="center">@onmax/nuxt-better-auth</h1>
<h1 align="center">@nuxtjs/better-auth</h1>

<p align="center">Nuxt module for <a href="https://better-auth.com">Better Auth</a></p>

<p align="center">
<a href="https://npmjs.com/package/@onmax/nuxt-better-auth"><img src="https://img.shields.io/npm/v/@onmax/nuxt-better-auth/latest.svg?style=flat&colorA=020420&colorB=00DC82" alt="npm version"></a>
<a href="https://npm.chart.dev/@onmax/nuxt-better-auth"><img src="https://img.shields.io/npm/dm/@onmax/nuxt-better-auth.svg?style=flat&colorA=020420&colorB=00DC82" alt="npm downloads"></a>
<a href="https://npmjs.com/package/@onmax/nuxt-better-auth"><img src="https://img.shields.io/npm/l/@onmax/nuxt-better-auth.svg?style=flat&colorA=020420&colorB=00DC82" alt="License"></a>
<a href="https://npmjs.com/package/@nuxtjs/better-auth"><img src="https://img.shields.io/npm/v/@nuxtjs/better-auth/latest.svg?style=flat&colorA=020420&colorB=00DC82" alt="npm version"></a>
<a href="https://npm.chart.dev/@nuxtjs/better-auth"><img src="https://img.shields.io/npm/dm/@nuxtjs/better-auth.svg?style=flat&colorA=020420&colorB=00DC82" alt="npm downloads"></a>
<a href="https://npmjs.com/package/@nuxtjs/better-auth"><img src="https://img.shields.io/npm/l/@nuxtjs/better-auth.svg?style=flat&colorA=020420&colorB=00DC82" alt="License"></a>
<a href="https://nuxt.com"><img src="https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js" alt="Nuxt"></a>
</p>

Expand All @@ -20,7 +20,7 @@

## Documentation

**[nuxt-better-auth.onmax.me](https://nuxt-better-auth.onmax.me/)**
**[better-auth.nuxtjs.org](https://better-auth.nuxtjs.org)**

## License

Expand Down
2 changes: 1 addition & 1 deletion docs/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default defineAppConfig({
github: {
url: 'https://github.com/onmax/nuxt-better-auth',
url: 'https://github.com/nuxt-modules/better-auth',
branch: 'main',
rootDir: 'docs',
},
Expand Down
2 changes: 1 addition & 1 deletion docs/app/components/OgImage/OgImageDocs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ defineProps<{
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24">
<path fill="currentColor" d="M12 2A10 10 0 0 0 2 12c0 4.42 2.87 8.17 6.84 9.5c.5.08.66-.23.66-.5v-1.69c-2.77.6-3.36-1.34-3.36-1.34c-.46-1.16-1.11-1.47-1.11-1.47c-.91-.62.07-.6.07-.6c1 .07 1.53 1.03 1.53 1.03c.87 1.52 2.34 1.07 2.91.83c.09-.65.35-1.09.63-1.34c-2.22-.25-4.55-1.11-4.55-4.92c0-1.11.38-2 1.03-2.71c-.1-.25-.45-1.29.1-2.64c0 0 .84-.27 2.75 1.02c.79-.22 1.65-.33 2.5-.33s1.71.11 2.5.33c1.91-1.29 2.75-1.02 2.75-1.02c.55 1.35.2 2.39.1 2.64c.65.71 1.03 1.6 1.03 2.71c0 3.82-2.34 4.66-4.57 4.91c.36.31.69.92.69 1.85V21c0 .27.16.59.67.5C19.14 20.16 22 16.42 22 12A10 10 0 0 0 12 2" />
</svg>
<span>github.com/onmax/nuxt-better-auth</span>
<span>github.com/nuxt-modules/better-auth</span>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/app/components/app/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const isDocsPage = computed(() => route.path.startsWith('/getting-started') || r

const navLinks = [
{ name: 'docs', path: '/getting-started' },
{ name: 'demo', path: 'https://demo-nuxt-better-auth.onmax.me', external: true },
{ name: 'demo', path: 'https://demo.better-auth.nuxtjs.org', external: true },
{ name: 'better-auth', path: 'https://www.better-auth.com', external: true },
]
</script>
Expand Down Expand Up @@ -59,7 +59,7 @@ const navLinks = [
</template>
<li class="relative group list-none h-full">
<NuxtLink
to="https://github.com/onmax/nuxt-better-auth"
to="https://github.com/nuxt-modules/better-auth"
target="_blank"
class="flex items-center h-full px-5 border-l border-[var(--ui-border)] text-muted transition-colors group-hover:text-[var(--ui-text)]"
aria-label="GitHub"
Expand Down
12 changes: 6 additions & 6 deletions docs/app/components/content/landing/LandingHero.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ function getCodeBlock(tab: { name: string, code: string }) {
<span class="italic text-amber-600">x</span>
</p>
<p class="relative inline tracking-tight opacity-90 md:text-sm text-xs dark:text-white font-mono text-black select-all">
npx nuxi module add <span class="relative dark:text-fuchsia-300 text-fuchsia-800">@onmax/nuxt-better-auth@alpha</span>
npx nuxi module add <span class="relative dark:text-fuchsia-300 text-fuchsia-800">@nuxtjs/better-auth@alpha</span>
</p>
</div>
<div class="flex gap-2 items-center">
<NuxtLink to="https://www.npmjs.com/package/@onmax/nuxt-better-auth" target="_blank" class="opacity-60 hover:opacity-100 transition-opacity">
<NuxtLink to="https://www.npmjs.com/package/@nuxtjs/better-auth" target="_blank" class="opacity-60 hover:opacity-100 transition-opacity">
<UIcon name="i-simple-icons-npm" class="size-4 text-red-500" />
</NuxtLink>
<NuxtLink to="https://github.com/onmax/nuxt-better-auth" target="_blank" class="opacity-60 hover:opacity-100 transition-opacity">
<NuxtLink to="https://github.com/nuxt-modules/better-auth" target="_blank" class="opacity-60 hover:opacity-100 transition-opacity">
<UIcon name="i-simple-icons-github" class="size-4" />
</NuxtLink>
</div>
Expand All @@ -99,7 +99,7 @@ function getCodeBlock(tab: { name: string, code: string }) {
Get Started
</NuxtLink>
<NuxtLink
to="https://github.com/onmax/nuxt-better-auth"
to="https://github.com/nuxt-modules/better-auth"
target="_blank"
class="group relative hidden p-px text-xs font-semibold leading-6 text-white no-underline md:inline-block"
>
Expand All @@ -114,7 +114,7 @@ function getCodeBlock(tab: { name: string, code: string }) {
</NuxtLink>
<!-- Mobile GitHub button -->
<NuxtLink
to="https://github.com/onmax/nuxt-better-auth"
to="https://github.com/nuxt-modules/better-auth"
target="_blank"
class="flex items-center gap-2 rounded-none bg-zinc-950 px-4 py-2 text-xs font-semibold text-white ring-1 ring-white/10 md:hidden"
>
Expand Down Expand Up @@ -203,7 +203,7 @@ function getCodeBlock(tab: { name: string, code: string }) {
<!-- Demo CTA (bottom-right) -->
<motion.div layout class="self-end mt-3">
<NuxtLink
to="https://demo-nuxt-better-auth.onmax.me/"
to="https://demo.better-auth.nuxtjs.org"
target="_blank"
class="shadow-md border dark:border-stone-700 border-stone-300 mb-4 ml-auto mr-4 mt-auto flex cursor-pointer items-center gap-2 px-3 py-1 transition-all ease-in-out hover:opacity-70"
>
Expand Down
6 changes: 3 additions & 3 deletions docs/app/components/content/landing/hero.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ tabs:
- name: nuxt.config.ts
code: |
export default defineNuxtConfig({
modules: ['@onmax/nuxt-better-auth'],
modules: ['@nuxtjs/better-auth'],
routeRules: {
'/dashboard/**': { auth: 'user' },
'/admin/**': { auth: 'admin' },
},
})
- name: server/auth.config.ts
code: |
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'
import { admin, twoFactor } from 'better-auth/plugins'

export default defineServerAuth({
Expand All @@ -25,7 +25,7 @@ tabs:
})
- name: app/auth.config.ts
code: |
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'
import { defineClientAuth } from '@nuxtjs/better-auth/config'
import { adminClient, twoFactorClient } from 'better-auth/client/plugins'

export default defineClientAuth({
Expand Down
8 changes: 4 additions & 4 deletions docs/content/1.getting-started/0.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ navigation.icon: i-lucide-sparkles

Nuxt Better Auth integrates **Nuxt** and **Better Auth**, the TypeScript-first authentication library. You get route protection, session management, and schema generation with minimal setup. The plugin ecosystem adds features like 2FA, organizations, and passkeys.

::card{to="https://demo-nuxt-better-auth.nuxt.dev" target="_blank" icon="i-lucide-external-link"}
::card{to="https://demo.better-auth.nuxtjs.org" target="_blank" icon="i-lucide-external-link"}
**Live Demo** – Try the authentication flow in action.
::

Expand Down Expand Up @@ -58,7 +58,7 @@ Get a working login in 5 minutes with NuxtHub (SQLite).
### Install

```bash
npx nuxi module add @onmax/nuxt-better-auth@alpha @nuxthub/core
npx nuxi module add @nuxtjs/better-auth@alpha @nuxthub/core
```

### Configure
Expand All @@ -76,15 +76,15 @@ BETTER_AUTH_SECRET="generate-a-32-char-secret"
### Create Config Files

```ts [server/auth.config.ts]
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'

export default defineServerAuth({
emailAndPassword: { enabled: true },
})
```

```ts [app/auth.config.ts]
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'
import { defineClientAuth } from '@nuxtjs/better-auth/config'

export default defineClientAuth({})
```
Expand Down
6 changes: 3 additions & 3 deletions docs/content/1.getting-started/1.installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ navigation.icon: i-lucide-download
### Install the module

```bash
npx nuxi module add @onmax/nuxt-better-auth@alpha
npx nuxi module add @nuxtjs/better-auth@alpha
```

### Set Environment Variables
Expand Down Expand Up @@ -69,15 +69,15 @@ The module requires two configuration files:
Create these files with the following content:

```ts [server/auth.config.ts]
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'

export default defineServerAuth({
emailAndPassword: { enabled: true }
})
```

```ts [app/auth.config.ts]
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'
import { defineClientAuth } from '@nuxtjs/better-auth/config'

export default defineClientAuth({})
```
Expand Down
6 changes: 3 additions & 3 deletions docs/content/1.getting-started/2.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ navigation.icon: i-lucide-settings

```ts [nuxt.config.ts]
export default defineNuxtConfig({
modules: ['@onmax/nuxt-better-auth'],
modules: ['@nuxtjs/better-auth'],
auth: {
redirects: {
login: '/login',
Expand Down Expand Up @@ -82,7 +82,7 @@ Define your authentication logic in `server/auth.config.ts`, including plugins,
Use the `defineServerAuth` helper to ensure type safety and access context. It accepts an object or function syntax.

```ts [server/auth.config.ts]
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'

// Object syntax (simplest)
export default defineServerAuth({
Expand All @@ -106,7 +106,7 @@ The module automatically injects `secret` and `baseURL`. You don't need to confi
When using the function syntax, `defineServerAuth` callback receives a context object with useful properties:

```ts [server/auth.config.ts]
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'
import { drizzleAdapter } from 'better-auth/adapters/drizzle'

export default defineServerAuth(({ db, runtimeConfig }) => ({
Expand Down
6 changes: 3 additions & 3 deletions docs/content/1.getting-started/3.client-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Create `app/auth.config.ts` with a default export using `defineClientAuth`.
The `defineClientAuth` helper supports two syntaxes: an object for simple configurations, or a function when you need access to context like the resolved site URL.

```ts [app/auth.config.ts]
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'
import { defineClientAuth } from '@nuxtjs/better-auth/config'

// Object syntax (simplest)
export default defineClientAuth({})
Expand All @@ -31,7 +31,7 @@ The helper creates a factory function that the module calls with the correct `ba
If you added a plugin in your server config (`server/auth.config.ts`), make sure to add its client equivalent here.

```ts [app/auth.config.ts]
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'
import { defineClientAuth } from '@nuxtjs/better-auth/config'
import { adminClient } from 'better-auth/client/plugins'

export default defineClientAuth({
Expand All @@ -46,7 +46,7 @@ export default defineClientAuth({
### Admin + Two Factor

```ts [app/auth.config.ts]
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'
import { defineClientAuth } from '@nuxtjs/better-auth/config'
import { adminClient, twoFactorClient } from 'better-auth/client/plugins'

export default defineClientAuth({
Expand Down
2 changes: 1 addition & 1 deletion docs/content/1.getting-started/4.type-augmentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If you add the `admin` plugin:

```ts [server/auth.config.ts]
import { admin } from 'better-auth/plugins'
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'

export default defineServerAuth({
plugins: [admin()]
Expand Down
2 changes: 1 addition & 1 deletion docs/content/2.core-concepts/2.sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const { fetchSession, ready } = useUserSession()
Configure session duration in your auth config:

```ts [server/auth.config.ts]
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'

export default defineServerAuth({
session: {
Expand Down
2 changes: 1 addition & 1 deletion docs/content/2.core-concepts/5.security-caveats.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Client-side redirects improve UX but don't prevent unauthorized access. Always v
Better Auth performs origin checks for cookie-based requests (it validates `Origin` / `Referer`). If you use multiple domains (custom domains, preview URLs, etc.), add them to `trustedOrigins` in your auth config.

```ts [server/auth.config.ts]
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'

export default defineServerAuth({
trustedOrigins: [
Expand Down
2 changes: 1 addition & 1 deletion docs/content/3.guides/1.role-based-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: Protect routes using generic field matching on AuthUser.

```ts [server/auth.config.ts]
import { admin } from 'better-auth/plugins'
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'
export default defineServerAuth({ plugins: [admin()] })

// nuxt.config.ts - role is now typed!
Expand Down
2 changes: 1 addition & 1 deletion docs/content/3.guides/2.oauth-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ GOOGLE_CLIENT_SECRET="your-client-secret"
### Configure `server/auth.config.ts`

```ts [server/auth.config.ts]
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'

export default defineServerAuth({
socialProviders: {
Expand Down
8 changes: 4 additions & 4 deletions docs/content/3.guides/3.custom-database.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Adapter imports come from the `better-auth` package, so you must install it in y
pnpm add better-auth
```

`better-auth` is a peer dependency of `@onmax/nuxt-better-auth`. Keep the major versions aligned to avoid mismatches.
`better-auth` is a peer dependency of `@nuxtjs/better-auth`. Keep the major versions aligned to avoid mismatches.

## Drizzle Adapter

```ts [server/auth.config.ts]
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'
import { drizzleAdapter } from 'better-auth/adapters/drizzle'
import { drizzle } from 'drizzle-orm/node-postgres'

Expand All @@ -41,7 +41,7 @@ export default defineServerAuth({
## Prisma Adapter

```ts [server/auth.config.ts]
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'
import { prismaAdapter } from 'better-auth/adapters/prisma'
import { PrismaClient } from '@prisma/client'

Expand All @@ -56,7 +56,7 @@ export default defineServerAuth({
## Kysely Adapter

```ts [server/auth.config.ts]
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'
import { kyselyAdapter } from 'better-auth/adapters/kysely'
import { Kysely, PostgresDialect } from 'kysely'
import { Pool } from 'pg'
Expand Down
4 changes: 2 additions & 2 deletions docs/content/3.guides/4.database-less-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Simply don't configure a database adapter:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
modules: ['@onmax/nuxt-better-auth'],
modules: ['@nuxtjs/better-auth'],
})
```

Expand All @@ -64,7 +64,7 @@ export default defineNuxtConfig({
Enable JWE sessions and cookie-based OAuth state:

```ts [server/auth.config.ts]
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'

export default defineServerAuth({
socialProviders: {
Expand Down
2 changes: 1 addition & 1 deletion docs/content/3.guides/5.external-auth-backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ When your Better Auth server runs on a separate backend (e.g., standalone h3/Nit

```ts [nuxt.config.ts]
export default defineNuxtConfig({
modules: ['@onmax/nuxt-better-auth'],
modules: ['@nuxtjs/better-auth'],
auth: {
clientOnly: true,
},
Expand Down
6 changes: 3 additions & 3 deletions docs/content/3.guides/6.migrate-from-nuxt-auth-utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default defineOAuthGitHubEventHandler({
```ts
// nuxt-better-auth - Declarative config
// server/auth.config.ts
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'
export default defineServerAuth({
socialProviders: {
github: {
Expand Down Expand Up @@ -107,7 +107,7 @@ export default defineOAuthGitHubEventHandler({
**After:**

```ts [server/auth.config.ts]
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'

export default defineServerAuth({
socialProviders: {
Expand Down Expand Up @@ -257,7 +257,7 @@ Implement a custom password verifier that tries both formats:

```ts [server/auth.config.ts]
import { scrypt, timingSafeEqual } from 'node:crypto'
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
import { defineServerAuth } from '@nuxtjs/better-auth/config'

async function verifyLegacyHash(password: string, hash: string): Promise<boolean> {
// Implement scrypt verification for legacy hashes
Expand Down
Loading
Loading