mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-09 20:27:44 +00:00
docs: move options to interface
This commit is contained in:
@@ -13,6 +13,9 @@ import { Features } from "@/components/blocks/features";
|
|||||||
import { ForkButton } from "@/components/fork-button";
|
import { ForkButton } from "@/components/fork-button";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import defaultMdxComponents from "fumadocs-ui/mdx";
|
import defaultMdxComponents from "fumadocs-ui/mdx";
|
||||||
|
import { createTypeTable } from "fumadocs-typescript/ui";
|
||||||
|
|
||||||
|
const { AutoTypeTable } = createTypeTable();
|
||||||
|
|
||||||
export default async function Page({
|
export default async function Page({
|
||||||
params,
|
params,
|
||||||
@@ -65,6 +68,7 @@ export default async function Page({
|
|||||||
Steps,
|
Steps,
|
||||||
Tab,
|
Tab,
|
||||||
Tabs,
|
Tabs,
|
||||||
|
AutoTypeTable,
|
||||||
GenerateSecret,
|
GenerateSecret,
|
||||||
AnimatePresence,
|
AnimatePresence,
|
||||||
TypeTable,
|
TypeTable,
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ export const InfiniteMovingCards = ({
|
|||||||
<svg
|
<svg
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
stroke-width="0"
|
strokeWidth="0"
|
||||||
viewBox="0 0 512 512"
|
viewBox="0 0 512 512"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
className="w-full"
|
className="w-full"
|
||||||
@@ -116,7 +116,7 @@ export const InfiniteMovingCards = ({
|
|||||||
<svg
|
<svg
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
stroke-width="0"
|
strokeWidth="0"
|
||||||
viewBox="0 0 448 512"
|
viewBox="0 0 448 512"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
className="w-full"
|
className="w-full"
|
||||||
|
|||||||
@@ -121,7 +121,18 @@ authClient.verifyEmail({
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Auto SignIn After Verification
|
||||||
|
|
||||||
|
To sign in the user automatically after they successfully verify their email, set the `autoSignInAfterVerification` option to `true`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const auth = betterAuth({
|
||||||
|
//...your other options
|
||||||
|
emailVerification: {
|
||||||
|
autoSignInAfterVerification: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
## Password Reset Email
|
## Password Reset Email
|
||||||
|
|
||||||
|
|||||||
@@ -3,293 +3,7 @@ title: Options
|
|||||||
description: Better Auth Configuration Options
|
description: Better Auth Configuration Options
|
||||||
---
|
---
|
||||||
|
|
||||||
List of all the available options for configuring Better Auth.
|
List of all the available options for configuring Better Auth. See [Better Auth Options](https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/types/options.ts#L13).
|
||||||
|
|
||||||
### `appName`
|
|
||||||
|
|
||||||
`string` (default: `Better Auth`) - Name of the application.
|
|
||||||
|
|
||||||
### `baseURL`
|
|
||||||
|
|
||||||
`string` (default: `/`) - Base URL for the Better Auth. This is typically the root URL where your application server is hosted. If not explicitly set, Better Auth check the following environment variable: `BETTER_AUTH_URL`.
|
|
||||||
|
|
||||||
### `basePath`
|
|
||||||
|
|
||||||
`string` (default: `/api/auth`) - Base path for the Better Auth API. This is the path where Better Auth API will be mounted.
|
|
||||||
|
|
||||||
### `secret`
|
|
||||||
|
|
||||||
`string` - Random value used by the library for encryption and generating hashes.
|
|
||||||
|
|
||||||
|
|
||||||
### `database`
|
<AutoTypeTable path="./lib/auth.ts" name="BetterAuthOptions" />
|
||||||
|
|
||||||
`DatabaseOptions` - Database configuration options. By defualt it supports, `betterSqlite3` instance, `Mysql2` pool, and `pg` pool. You can also pass a kysely dialect, a kysely instance, or an orm adapter.
|
|
||||||
|
|
||||||
Refer to the [Database](/docs/concept/database) section for more information.
|
|
||||||
|
|
||||||
### `emailAndPassword`
|
|
||||||
|
|
||||||
`EmailAndPasswordOptions` - Email and password configuration options.
|
|
||||||
|
|
||||||
<TypeTable
|
|
||||||
type={{
|
|
||||||
enabled: {
|
|
||||||
description: "Enable email and password authentication.",
|
|
||||||
type: 'boolean',
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
autoSignIn: {
|
|
||||||
description: "Automatically login after successfull signup",
|
|
||||||
type: 'boolean',
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
minPasswordLength: {
|
|
||||||
description: "Minimum length of the password.",
|
|
||||||
type: 'number',
|
|
||||||
default: 8
|
|
||||||
},
|
|
||||||
maxPasswordLength: {
|
|
||||||
description: "Maximum length of the password.",
|
|
||||||
type: 'number',
|
|
||||||
default: 128
|
|
||||||
},
|
|
||||||
sendResetPasswordToken: {
|
|
||||||
description: "Send reset password token to user's email.",
|
|
||||||
type: '(token: string, user: User) => Promise<void>',
|
|
||||||
},
|
|
||||||
resetPasswordTokenExpiresIn: {
|
|
||||||
description: "Expiration time for the reset password token. The value should be in seconds.",
|
|
||||||
type: 'number',
|
|
||||||
default: 60 * 60 * 1 // 1 hour
|
|
||||||
},
|
|
||||||
sendVerificationEmail: {
|
|
||||||
description: "Send verification email to user's email. It takes email and data that contains `url` and `token` props.",
|
|
||||||
type: `(email: string, data: Data) => Promise<void>`
|
|
||||||
},
|
|
||||||
sendEmailVerificationOnSignUp: {
|
|
||||||
description: "Trigger email verification on sign up. If set to true, `sendVerificationEmail` function must be provided.",
|
|
||||||
type: 'boolean',
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
password: {
|
|
||||||
description: "Custom password hashing function. ",
|
|
||||||
type: `{
|
|
||||||
hash: Function,
|
|
||||||
verify: Function
|
|
||||||
}`,
|
|
||||||
default: "scrypt"
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
### `socialProviders`
|
|
||||||
|
|
||||||
a configuration object that contains the configuration for social providers.
|
|
||||||
|
|
||||||
```ts title="auth.ts"
|
|
||||||
const auth = betterAuth({
|
|
||||||
socialProviders: {
|
|
||||||
google: {
|
|
||||||
clientId: process.env.GOOGLE_CLIENT_ID as string,
|
|
||||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
|
|
||||||
},
|
|
||||||
github: {
|
|
||||||
clientId: process.env.GITHUB_CLIENT_ID as string,
|
|
||||||
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
### `plugins`
|
|
||||||
|
|
||||||
`Plugin[]` - List of plugins to use with Better Auth.
|
|
||||||
|
|
||||||
### `user`
|
|
||||||
|
|
||||||
`UserOptions` - User configuration options.
|
|
||||||
|
|
||||||
<TypeTable
|
|
||||||
type={{
|
|
||||||
modelName: {
|
|
||||||
description: "Name of the user model (table).",
|
|
||||||
type: 'string',
|
|
||||||
default: 'user'
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
### `session`
|
|
||||||
|
|
||||||
`SessionOptions` - Session configuration options.
|
|
||||||
|
|
||||||
<TypeTable
|
|
||||||
type={{
|
|
||||||
modelName: {
|
|
||||||
description: "Name of the session model (table).",
|
|
||||||
type: 'string',
|
|
||||||
default: 'session'
|
|
||||||
},
|
|
||||||
expiresIn: {
|
|
||||||
description: "Expiration time for the session token. The value should be in seconds.",
|
|
||||||
type: 'number',
|
|
||||||
default: "7 days (60 * 60 * 24 * 7)"
|
|
||||||
},
|
|
||||||
updateAge: {
|
|
||||||
description: "Time after which the session token will be updated. The value should be in seconds. If set to 0, the session will be updated everytiem it's used.",
|
|
||||||
type: 'number',
|
|
||||||
default: "1 day (60 * 60 * 24)"
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
### `account`
|
|
||||||
|
|
||||||
`AccountOptions` - Account configuration options.
|
|
||||||
|
|
||||||
<TypeTable
|
|
||||||
type={{
|
|
||||||
modelName: {
|
|
||||||
description: "Name of the account model (table).",
|
|
||||||
type: 'string',
|
|
||||||
default: 'account'
|
|
||||||
},
|
|
||||||
accountLinking: {
|
|
||||||
description: "Account linking configuration options.",
|
|
||||||
type: "AccountLinkingOptions"
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
#### `accountLinking`
|
|
||||||
|
|
||||||
`AccountLinkingOptions` - Account linking configuration options.
|
|
||||||
|
|
||||||
<TypeTable
|
|
||||||
type={{
|
|
||||||
enabled: {
|
|
||||||
description: "Enable account linking.",
|
|
||||||
type: 'boolean',
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
requireEmailVerified: {
|
|
||||||
description: "Require email verification to link account.",
|
|
||||||
type: 'boolean',
|
|
||||||
default: true
|
|
||||||
},
|
|
||||||
trustedProviders: {
|
|
||||||
description: "List of providers that can be linked without verifying the user's email.",
|
|
||||||
type: 'string[]',
|
|
||||||
default: '[]'
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
### `rateLimit`
|
|
||||||
|
|
||||||
`RateLimitOptions` - Rate limiting configuration options.
|
|
||||||
|
|
||||||
<TypeTable
|
|
||||||
type={{
|
|
||||||
windowMs: {
|
|
||||||
description: "Time window for rate limiting. The value should be in milliseconds.",
|
|
||||||
type: 'number',
|
|
||||||
default: 15 * 60 * 1000
|
|
||||||
},
|
|
||||||
max: {
|
|
||||||
description: "Maximum number of requests allowed in the window.",
|
|
||||||
type: 'number',
|
|
||||||
default: 100
|
|
||||||
},
|
|
||||||
customRules: {
|
|
||||||
description: "Custom rate limiting rules.",
|
|
||||||
type: "Record<string, RateLimitOptions>"
|
|
||||||
},
|
|
||||||
storage: {
|
|
||||||
description: "Storage for rate limiting data.",
|
|
||||||
type: "'memory' | 'database'",
|
|
||||||
default: 'memory'
|
|
||||||
},
|
|
||||||
tableName: {
|
|
||||||
description: "Name of the table to store rate limiting data. Applied when `storage` is set to `database`.",
|
|
||||||
type: 'string',
|
|
||||||
default: 'rateLimit'
|
|
||||||
},
|
|
||||||
customStorage: {
|
|
||||||
description: "Custom storage for rate limiting data.",
|
|
||||||
type: 'RateLimitStorage'
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
### `trustedOrigins`
|
|
||||||
|
|
||||||
list of trusted origins. This is very important to prevent CSRF attacks and open redirects.
|
|
||||||
|
|
||||||
```ts title="auth.ts"
|
|
||||||
const auth = betterAuth({
|
|
||||||
trustedOrigins: [
|
|
||||||
'https://example.com',
|
|
||||||
'https://app.example.com'
|
|
||||||
]
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
### `advanced`
|
|
||||||
|
|
||||||
`AdvancedOptions` - Advanced configuration options.
|
|
||||||
|
|
||||||
|
|
||||||
<TypeTable
|
|
||||||
type={{
|
|
||||||
useSecureCookies: {
|
|
||||||
description: "Use secure cookies. By default, when base URL is `https` secure cookies are used.",
|
|
||||||
type: 'boolean',
|
|
||||||
default: `true (if base URL is 'https')`
|
|
||||||
},
|
|
||||||
disableCSRFCheck: {
|
|
||||||
description: "Disable csrf protection checks. ⚠︎ only use this if you know what you are doing.",
|
|
||||||
type: 'boolean',
|
|
||||||
default: false
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
|
|
||||||
### `onAPIError`
|
|
||||||
|
|
||||||
`OnAPIErrorOptions` - Options for handling API errors.
|
|
||||||
|
|
||||||
<TypeTable
|
|
||||||
type={{
|
|
||||||
throw: {
|
|
||||||
description: "Throw the error.",
|
|
||||||
type: 'boolean',
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
onError: {
|
|
||||||
description: "Custom error handler.",
|
|
||||||
type: '(error: Error, ctx: APIContext) => void'
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
### `logger`
|
|
||||||
|
|
||||||
`LoggerOptions` - Logger configuration options.
|
|
||||||
|
|
||||||
<TypeTable
|
|
||||||
type={{
|
|
||||||
disabled: {
|
|
||||||
description: "Disable logging.",
|
|
||||||
type: 'boolean',
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
verboseLogging: {
|
|
||||||
description: "Enable verbose logging.",
|
|
||||||
type: 'boolean',
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
3
docs/lib/auth.ts
Normal file
3
docs/lib/auth.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { BetterAuthOptions } from "better-auth";
|
||||||
|
|
||||||
|
export { type BetterAuthOptions };
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
"fumadocs-docgen": "^1.1.0",
|
"fumadocs-docgen": "^1.1.0",
|
||||||
"fumadocs-mdx": "11.1.0",
|
"fumadocs-mdx": "11.1.0",
|
||||||
"fumadocs-twoslash": "^1.1.2",
|
"fumadocs-twoslash": "^1.1.2",
|
||||||
"fumadocs-typescript": "^2.1.0",
|
"fumadocs-typescript": "^3.0.2",
|
||||||
"fumadocs-ui": "14.0.2",
|
"fumadocs-ui": "14.0.2",
|
||||||
"geist": "^1.3.1",
|
"geist": "^1.3.1",
|
||||||
"input-otp": "^1.2.4",
|
"input-otp": "^1.2.4",
|
||||||
|
|||||||
20
pnpm-lock.yaml
generated
20
pnpm-lock.yaml
generated
@@ -476,8 +476,8 @@ importers:
|
|||||||
specifier: ^1.1.2
|
specifier: ^1.1.2
|
||||||
version: 1.1.3(fumadocs-ui@14.0.2(@types/react-dom@18.3.1)(@types/react@18.3.12)(next@15.0.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(shiki@1.22.2)(typescript@5.6.3)
|
version: 1.1.3(fumadocs-ui@14.0.2(@types/react-dom@18.3.1)(@types/react@18.3.12)(next@15.0.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(shiki@1.22.2)(typescript@5.6.3)
|
||||||
fumadocs-typescript:
|
fumadocs-typescript:
|
||||||
specifier: ^2.1.0
|
specifier: ^3.0.2
|
||||||
version: 2.1.0(typescript@5.6.3)
|
version: 3.0.2(typescript@5.6.3)
|
||||||
fumadocs-ui:
|
fumadocs-ui:
|
||||||
specifier: 14.0.2
|
specifier: 14.0.2
|
||||||
version: 14.0.2(@types/react-dom@18.3.1)(@types/react@18.3.12)(next@15.0.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
version: 14.0.2(@types/react-dom@18.3.1)(@types/react@18.3.12)(next@15.0.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||||
@@ -10309,11 +10309,6 @@ packages:
|
|||||||
fumadocs-ui: 13.x.x
|
fumadocs-ui: 13.x.x
|
||||||
shiki: 1.x.x
|
shiki: 1.x.x
|
||||||
|
|
||||||
fumadocs-typescript@2.1.0:
|
|
||||||
resolution: {integrity: sha512-fxxC8F+bQQxlVQA03vWaoztJFeKkevW3WgT7ECPCmdOB2UFsRB61cgzlRvwKqtFWJuJYASX55+2wEMxXAjzBjQ==}
|
|
||||||
peerDependencies:
|
|
||||||
typescript: '*'
|
|
||||||
|
|
||||||
fumadocs-typescript@3.0.2:
|
fumadocs-typescript@3.0.2:
|
||||||
resolution: {integrity: sha512-SqYJy+NxjjuQQeom7wLpODYiWtIKWfndguHL3XKXaMUvhlsjmsWWTaXJWKaqIfOStiYJQlGWrXxFA2Rrpbx63Q==}
|
resolution: {integrity: sha512-SqYJy+NxjjuQQeom7wLpODYiWtIKWfndguHL3XKXaMUvhlsjmsWWTaXJWKaqIfOStiYJQlGWrXxFA2Rrpbx63Q==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@@ -28196,17 +28191,6 @@ snapshots:
|
|||||||
- supports-color
|
- supports-color
|
||||||
- typescript
|
- typescript
|
||||||
|
|
||||||
fumadocs-typescript@2.1.0(typescript@5.6.3):
|
|
||||||
dependencies:
|
|
||||||
fast-glob: 3.3.2
|
|
||||||
hast-util-to-jsx-runtime: 2.3.2
|
|
||||||
mdast-util-from-markdown: 2.0.2
|
|
||||||
mdast-util-gfm: 3.0.0
|
|
||||||
mdast-util-to-hast: 13.2.0
|
|
||||||
typescript: 5.6.3
|
|
||||||
transitivePeerDependencies:
|
|
||||||
- supports-color
|
|
||||||
|
|
||||||
fumadocs-typescript@3.0.2(typescript@5.6.3):
|
fumadocs-typescript@3.0.2(typescript@5.6.3):
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 22.8.1
|
'@types/node': 22.8.1
|
||||||
|
|||||||
Reference in New Issue
Block a user