Skip to content

Commit e82fd62

Browse files
committed
docs: simplify structure, fix UI issues, add custom db guide
1 parent a6adc56 commit e82fd62

17 files changed

Lines changed: 332 additions & 522 deletions

File tree

docs/app/components/content/landing/LandingFeatures.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const items = features.items as { title: string, description: string, icon: stri
3737
<div class="mt-2">
3838
<p class="mt-2 text-sm text-left text-muted">
3939
{{ feature.description }}
40-
<NuxtLink class="ml-2 underline" to="/getting-started/installation">
40+
<NuxtLink class="underline" to="/getting-started/installation">
4141
Learn more
4242
</NuxtLink>
4343
</p>

docs/app/components/content/landing/LandingHero.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function getCodeBlock(tab: { name: string, code: string }) {
9393
<div class="mt-4 flex w-fit flex-col gap-4 font-sans md:flex-row md:justify-center lg:justify-start items-center">
9494
<NuxtLink
9595
to="/getting-started/installation"
96-
class="border-2 border-black bg-white px-4 py-1.5 text-sm uppercase text-black shadow-[1px_1px_rgba(0,0,0),2px_2px_rgba(0,0,0),3px_3px_rgba(0,0,0),4px_4px_rgba(0,0,0),5px_5px_0px_0px_rgba(0,0,0)] transition duration-200 md:px-8 hover:shadow-sm dark:border-stone-100 dark:hover:shadow-sm dark:shadow-[1px_1px_rgba(255,255,255),2px_2px_rgba(255,255,255),3px_3px_rgba(255,255,255),4px_4px_rgba(255,255,255),5px_5px_0px_0px_rgba(255,255,255)]"
96+
class="border-2 border-black bg-white px-4 py-1.5 text-sm uppercase text-black shadow-[1px_1px_rgba(0,0,0),2px_2px_rgba(0,0,0),3px_3px_rgba(0,0,0),4px_4px_rgba(0,0,0),5px_5px_0px_0px_rgba(0,0,0)] transition duration-200 md:px-8 hover:shadow-sm dark:border-stone-400 dark:hover:shadow-sm dark:shadow-[1px_1px_rgba(120,113,108),2px_2px_rgba(120,113,108),3px_3px_rgba(120,113,108),4px_4px_rgba(120,113,108),5px_5px_0px_0px_rgba(120,113,108)]"
9797
>
9898
Get Started
9999
</NuxtLink>

docs/app/composables/useSidebarConfig.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,38 @@ export function useSidebarConfig() {
2222
{ title: 'Installation', href: '/getting-started/installation', icon: 'i-solar-download-square-bold' },
2323
{ title: 'Configuration', href: '/getting-started/configuration', icon: 'i-solar-settings-bold' },
2424
{ title: 'Client Setup', href: '/getting-started/client-setup', icon: 'i-solar-monitor-bold' },
25-
{ title: 'Type Augmentation', href: '/getting-started/type-augmentation', icon: 'i-solar-code-file-bold' },
26-
{ title: 'Schema Generation', href: '/getting-started/schema-generation', icon: 'i-solar-database-bold' },
2725
],
2826
},
2927
{
3028
title: 'Core Concepts',
3129
icon: 'i-solar-book-bookmark-bold',
3230
items: [
33-
{ title: 'How It Works', href: '/core-concepts/how-it-works', icon: 'i-solar-lightbulb-bolt-bold' },
31+
{ title: 'How It Works', href: '/getting-started/how-it-works', icon: 'i-solar-lightbulb-bolt-bold' },
3432
{ title: 'Server Auth', href: '/core-concepts/server-auth', icon: 'i-solar-server-bold' },
3533
{ title: 'Sessions', href: '/core-concepts/sessions', icon: 'i-solar-key-bold' },
3634
{ title: 'Route Protection', href: '/core-concepts/route-protection', icon: 'i-solar-shield-check-bold' },
37-
{ title: 'Auto Imports & Aliases', href: '/core-concepts/auto-imports-aliases', icon: 'i-solar-box-bold' },
38-
{ title: 'Security Caveats', href: '/core-concepts/security-caveats', icon: 'i-solar-danger-triangle-bold' },
35+
{ title: 'Auto Imports', href: '/core-concepts/auto-imports-aliases', icon: 'i-solar-box-bold' },
36+
{ title: 'Security', href: '/core-concepts/security-caveats', icon: 'i-solar-danger-triangle-bold' },
3937
],
4038
},
4139
{
4240
title: 'Guides',
4341
icon: 'i-solar-map-bold',
4442
items: [
45-
{ title: 'Role-Based Access', href: '/guides/role-based-access', icon: 'i-solar-users-group-rounded-bold' },
46-
{ title: 'API Protection', href: '/guides/api-protection', icon: 'i-solar-lock-bold' },
43+
{ title: 'Custom Database', href: '/guides/custom-database', icon: 'i-solar-database-bold' },
4744
{ title: 'Database-less Mode', href: '/guides/database-less-mode', icon: 'i-solar-cloud-bold' },
48-
{ title: 'Migrate from nuxt-auth-utils', href: '/guides/migrate-from-nuxt-auth-utils', icon: 'i-solar-transfer-horizontal-bold' },
45+
{ title: 'OAuth Providers', href: '/guides/oauth-providers', icon: 'i-solar-user-id-bold' },
46+
{ title: 'Role-Based Access', href: '/guides/role-based-access', icon: 'i-solar-users-group-rounded-bold' },
47+
{ title: 'Two-Factor Auth', href: '/guides/two-factor-auth', icon: 'i-solar-lock-bold' },
48+
{ title: 'Testing', href: '/guides/testing', icon: 'i-solar-test-tube-bold' },
49+
],
50+
},
51+
{
52+
title: 'Integrations',
53+
icon: 'i-solar-plug-circle-bold',
54+
items: [
55+
{ title: 'NuxtHub', href: '/integrations/nuxthub', icon: 'i-simple-icons-nuxtdotjs' },
56+
{ title: 'DevTools', href: '/integrations/devtools', icon: 'i-solar-tuning-square-bold' },
4957
],
5058
},
5159
{

docs/app/pages/[[lang]]/[...slug].vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ const editLink = computed(() => {
5555
<DocsPageFooter :surround="surround" :edit-link="editLink" />
5656
</UPageBody>
5757

58-
<template v-if="page?.body?.toc?.links?.length" #right>
59-
<UContentToc highlight :title="appConfig.toc?.title || t('docs.toc')" :links="page.body?.toc?.links">
58+
<template #right>
59+
<UContentToc v-if="page?.body?.toc?.links?.length" highlight :title="appConfig.toc?.title || t('docs.toc')" :links="page.body?.toc?.links">
6060
<template #bottom>
6161
<DocsAsideRightBottom />
6262
</template>

docs/content/1.getting-started/0.index.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,69 @@ Building authentication from scratch is hard. Wiring up Better Auth with Nuxt ma
4949

5050
This module does all of that for you. It's designed to be **drop-in** and **zero-config** where possible.
5151

52-
::callout{icon="i-lucide-rocket" to="/getting-started/quick-start"}
53-
Ready to start? Follow the **Quick Start**.
52+
## Quick Start
53+
54+
Get a working login in 5 minutes with NuxtHub (SQLite).
55+
56+
::steps
57+
58+
### Install
59+
60+
::code-group{sync="pm"}
61+
```bash [pnpm]
62+
pnpm add @onmax/nuxt-better-auth better-auth @nuxthub/core
63+
```
64+
```bash [npm]
65+
npm install @onmax/nuxt-better-auth better-auth @nuxthub/core
66+
```
67+
::
68+
69+
### Configure
70+
71+
```ts [nuxt.config.ts]
72+
export default defineNuxtConfig({
73+
modules: ['@nuxthub/core', '@onmax/nuxt-better-auth'],
74+
hub: { db: 'sqlite' },
75+
})
76+
```
77+
78+
```ini [.env]
79+
NUXT_BETTER_AUTH_SECRET="generate-a-32-char-secret"
80+
```
81+
82+
### Create Config Files
83+
84+
```ts [auth.config.ts]
85+
import { defineServerAuth } from '@onmax/nuxt-better-auth'
86+
87+
export default defineServerAuth(() => ({
88+
emailAndPassword: { enabled: true },
89+
}))
90+
```
91+
92+
```ts [client-auth.config.ts]
93+
import { createAuthClient } from 'better-auth/vue'
94+
95+
export function createAppAuthClient(baseURL: string) {
96+
return createAuthClient({ baseURL })
97+
}
98+
```
99+
100+
### Run
101+
102+
::code-group{sync="pm"}
103+
```bash [pnpm]
104+
pnpm dev
105+
```
106+
```bash [npm]
107+
npm run dev
108+
```
109+
::
110+
111+
::
112+
113+
You now have API routes at `/api/auth/*`, a reactive `useUserSession()` composable, and route protection via `definePageMeta`.
114+
115+
::callout{icon="i-lucide-arrow-right" to="/getting-started/installation"}
116+
Continue to **Installation** for detailed setup options.
54117
::

docs/content/1.getting-started/1.quick-start.md

Lines changed: 0 additions & 145 deletions
This file was deleted.

docs/content/1.getting-started/2.installation.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export function createAppAuthClient(baseURL: string) {
104104
**Need database persistence?** See [NuxtHub Integration](/integrations/nuxthub) for auto-generated schemas and full database support.
105105
::
106106

107+
::callout{icon="i-lucide-hard-drive" to="/guides/custom-database"}
108+
**Bring your own database?** Use Drizzle, Prisma, or Kysely adapters with any database.
109+
::
110+
107111
::callout{icon="i-lucide-arrow-right" to="/getting-started/configuration"}
108112
Continue to **Configuration** to set up these files.
109113
::

docs/content/1.getting-started/3.configuration.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,28 @@ NUXT_BETTER_AUTH_SECRET="your-super-secret-key"
104104
NUXT_PUBLIC_SITE_URL="http://localhost:3000"
105105
```
106106

107+
## For Module Authors
108+
109+
Other Nuxt modules can extend the authentication configuration:
110+
111+
```ts
112+
// In your Nuxt module
113+
export default defineNuxtModule({
114+
setup(options, nuxt) {
115+
nuxt.hook('better-auth:config:extend', (config) => {
116+
config.plugins = [...(config.plugins || []), myPlugin()]
117+
})
118+
}
119+
})
120+
```
121+
122+
Access sessions from server handlers:
123+
124+
```ts
125+
const { user, session } = await getUserSession(event)
126+
if (!user) throw createError({ statusCode: 401 })
127+
```
128+
107129
::callout{icon="i-lucide-arrow-right" to="/getting-started/client-setup"}
108130
Next, set up the **Client Configuration**.
109131
::

docs/content/2.core-concepts/2.sessions.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,62 @@ const { user, loggedIn, ready } = useUserSession()
4646
</template>
4747
```
4848

49-
For server-rendered pages that need immediate session access, see the [SSR Sessions Guide](/guides/ssr-sessions).
49+
## Server-Side Session Access
50+
51+
For pages that need session data during SSR without waiting for hydration:
52+
53+
```vue [pages/dashboard.vue]
54+
<script setup lang="ts">
55+
definePageMeta({ auth: 'user' })
56+
const { user, ready, fetchSession } = useUserSession()
57+
58+
if (import.meta.server) {
59+
await fetchSession({ headers: useRequestHeaders(['cookie']) })
60+
}
61+
</script>
62+
63+
<template>
64+
<BetterAuthState>
65+
<template #default>
66+
<p v-if="ready">Welcome {{ user?.name }}</p>
67+
</template>
68+
<template #placeholder>
69+
<p>Loading session...</p>
70+
</template>
71+
</BetterAuthState>
72+
</template>
73+
```
74+
75+
Without server-side session initialization, the page briefly shows a loading state before hydration completes.
76+
77+
## Session Refresh
78+
79+
Force refresh the session data:
80+
81+
```vue
82+
<script setup lang="ts">
83+
const { fetchSession, ready } = useUserSession()
84+
</script>
85+
86+
<template>
87+
<button :disabled="!ready" @click="fetchSession({ force: true })">
88+
Refresh session
89+
</button>
90+
</template>
91+
```
92+
93+
## Session Lifetime
94+
95+
Configure session duration in your auth config:
96+
97+
```ts [auth.config.ts]
98+
export default defineServerAuth(() => ({
99+
session: {
100+
cookie: {
101+
maxAge: 60 * 60 * 24 * 7, // 7 days
102+
},
103+
},
104+
}))
105+
```
50106

51107
:read-more{to="/api/components" title="BetterAuthState component"}

0 commit comments

Comments
 (0)