mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-18 11:32:15 -05:00
chore: docs optimizations
This commit is contained in:
@@ -114,7 +114,7 @@ If the user clicks the provided verification URL, their email is automatically v
|
||||
For manual verification, you can send the user a custom link with the `token` and call the `verifyEmail` function.
|
||||
|
||||
```ts
|
||||
authClient.verifyEmail({
|
||||
await authClient.verifyEmail({
|
||||
query: {
|
||||
token: "" // Pass the token here
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ To handle rate limit errors on the client side, you can manage them either globa
|
||||
```ts title="auth-client.ts"
|
||||
import { createAuthClient } from "better-auth/client";
|
||||
|
||||
export const authClient = createAuthClient({
|
||||
export const authClient = createAuthClient({
|
||||
fetchOptions: {
|
||||
onError: async (context) => {
|
||||
const { response } = context;
|
||||
@@ -178,7 +178,7 @@ export const authClient = createAuthClient({
|
||||
**Per Request Handling**
|
||||
|
||||
```ts title="auth-client.ts"
|
||||
import { client } from "./client";
|
||||
import { authClient } from "./auth-client";
|
||||
|
||||
await authClient.signIn.email({
|
||||
fetchOptions: {
|
||||
|
||||
@@ -187,7 +187,7 @@ const session = await authClient.getSession({ query: {
|
||||
or on the server
|
||||
|
||||
```ts title="server.ts"
|
||||
auth.api.getSession({
|
||||
await auth.api.getSession({
|
||||
query: {
|
||||
disableCookieCache: true,
|
||||
},
|
||||
@@ -232,7 +232,7 @@ const authClient = createAuthClient({
|
||||
plugins: [customSessionClient<typeof auth>()],
|
||||
});
|
||||
|
||||
const { data } = await authClient.useSession();
|
||||
const { data } = authClient.useSession();
|
||||
const { data: sessionData } = await authClient.getSession();
|
||||
// data.roles
|
||||
// data.user.newField
|
||||
|
||||
@@ -67,7 +67,7 @@ This plugin offers two main methods to do a second factor verification:
|
||||
import { createAuthClient } from "better-auth/client"
|
||||
import { twoFactorClient } from "better-auth/client/plugins"
|
||||
|
||||
const authClient = createAuthClient({
|
||||
export const authClient = createAuthClient({
|
||||
plugins: [
|
||||
twoFactorClient()
|
||||
]
|
||||
|
||||
@@ -55,7 +55,7 @@ The Anonymous plugin allows users to have an authenticated experience without re
|
||||
import { createAuthClient } from "better-auth/client"
|
||||
import { anonymousClient } from "better-auth/client/plugins"
|
||||
|
||||
const authClient = createAuthClient({
|
||||
export const authClient = createAuthClient({
|
||||
plugins: [
|
||||
anonymousClient()
|
||||
]
|
||||
|
||||
@@ -24,7 +24,7 @@ The API Key plugin allows you to create and manage API keys for your application
|
||||
import { betterAuth } from "better-auth"
|
||||
import { apiKey } from "better-auth/plugins"
|
||||
|
||||
const auth = betterAuth({
|
||||
export const auth = betterAuth({
|
||||
plugins: [ // [!code highlight]
|
||||
apiKey() // [!code highlight]
|
||||
] // [!code highlight]
|
||||
@@ -57,7 +57,7 @@ The API Key plugin allows you to create and manage API keys for your application
|
||||
import { createAuthClient } from "better-auth/client"
|
||||
import { apiKeyClient } from "better-auth/client/plugins"
|
||||
|
||||
const authClient = createAuthClient({
|
||||
export const authClient = createAuthClient({
|
||||
plugins: [ // [!code highlight]
|
||||
apiKeyClient() // [!code highlight]
|
||||
] // [!code highlight]
|
||||
|
||||
@@ -47,7 +47,7 @@ The **Captcha Plugin** integrates bot protection into your Better Auth system by
|
||||
"x-captcha-response": turnstileToken, // [!code highlight]
|
||||
"x-captcha-user-remote-ip": userIp, // optional: forwards the user's IP address to the captcha service // [!code highlight]
|
||||
}, // [!code highlight]
|
||||
},
|
||||
}, // [!code highlight]
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ The Email OTP plugin allows user to sign in, verify their email, or reset their
|
||||
import { createAuthClient } from "better-auth/client"
|
||||
import { emailOTPClient } from "better-auth/client/plugins"
|
||||
|
||||
const authClient = createAuthClient({
|
||||
export const authClient = createAuthClient({
|
||||
plugins: [
|
||||
emailOTPClient()
|
||||
]
|
||||
|
||||
@@ -46,7 +46,7 @@ The Generic OAuth plugin provides a flexible way to integrate authentication wit
|
||||
import { createAuthClient } from "better-auth/client"
|
||||
import { genericOAuthClient } from "better-auth/client/plugins"
|
||||
|
||||
const authClient = createAuthClient({
|
||||
export const authClient = createAuthClient({
|
||||
plugins: [
|
||||
genericOAuthClient()
|
||||
]
|
||||
|
||||
@@ -37,7 +37,7 @@ Magic link or email link is a way to authenticate users without a password. When
|
||||
```ts title="auth-client.ts"
|
||||
import { createAuthClient } from "better-auth/client";
|
||||
import { magicLinkClient } from "better-auth/client/plugins";
|
||||
const authClient = createAuthClient({
|
||||
export const authClient = createAuthClient({
|
||||
plugins: [
|
||||
magicLinkClient()
|
||||
]
|
||||
|
||||
@@ -30,7 +30,7 @@ export const auth = betterAuth({
|
||||
import { createAuthClient } from "better-auth/client"
|
||||
import { multiSessionClient } from "better-auth/client/plugins"
|
||||
|
||||
const authClient = createAuthClient({
|
||||
export const authClient = createAuthClient({
|
||||
plugins: [
|
||||
multiSessionClient()
|
||||
]
|
||||
|
||||
@@ -14,12 +14,12 @@ Add the One Tap plugin to your auth configuration:
|
||||
|
||||
```ts title="auth.ts"
|
||||
import { betterAuth } from "better-auth";
|
||||
import { oneTap } from "better-auth/plugins";
|
||||
import { oneTap } from "better-auth/plugins"; // [!code highlight]
|
||||
|
||||
export const auth = betterAuth({
|
||||
plugins: [
|
||||
oneTap(), // Add the One Tap server plugin
|
||||
]
|
||||
plugins: [ // [!code highlight]
|
||||
oneTap(), // Add the One Tap server plugin // [!code highlight]
|
||||
] // [!code highlight]
|
||||
});
|
||||
```
|
||||
|
||||
@@ -32,7 +32,7 @@ Add the client plugin and specify where the user should be redirected after sign
|
||||
import { createAuthClient } from "better-auth/client";
|
||||
import { oneTapClient } from "better-auth/client/plugins";
|
||||
|
||||
const authClient = createAuthClient({
|
||||
export const authClient = createAuthClient({
|
||||
plugins: [
|
||||
oneTapClient({
|
||||
clientId: "YOUR_CLIENT_ID",
|
||||
@@ -70,7 +70,7 @@ By default, after a successful login the plugin will hard redirect the user to `
|
||||
Pass fetchOptions with an onSuccess callback to handle the login response without a page reload:
|
||||
|
||||
```ts
|
||||
authClient.oneTap({
|
||||
await authClient.oneTap({
|
||||
fetchOptions: {
|
||||
onSuccess: () => {
|
||||
// For example, use a router to navigate without a full reload:
|
||||
@@ -85,7 +85,7 @@ authClient.oneTap({
|
||||
To perform a hard redirect to a different page after login, use the callbackURL option:
|
||||
|
||||
```ts
|
||||
authClient.oneTap({
|
||||
await authClient.oneTap({
|
||||
callbackURL: "/dashboard"
|
||||
});
|
||||
```
|
||||
@@ -97,7 +97,7 @@ If the user dismisses or skips the prompt, the plugin will retry showing the One
|
||||
If the maximum number of attempts is reached without a successful sign-in, you can use the onPromptNotification callback to be notified—allowing you to render an alternative UI (e.g., a traditional Google Sign-In button) so users can restart the process manually:
|
||||
|
||||
```ts
|
||||
authClient.oneTap({
|
||||
await authClient.oneTap({
|
||||
onPromptNotification: (notification) => {
|
||||
console.warn("Prompt was dismissed or skipped. Consider displaying an alternative sign-in option.", notification);
|
||||
// Render your alternative UI here
|
||||
|
||||
@@ -49,7 +49,7 @@ export const auth = betterAuth({
|
||||
import { createAuthClient } from "better-auth/client"
|
||||
import { organizationClient } from "better-auth/client/plugins"
|
||||
|
||||
const authClient = createAuthClient({
|
||||
export const authClient = createAuthClient({
|
||||
plugins: [ // [!code highlight]
|
||||
organizationClient() // [!code highlight]
|
||||
] // [!code highlight]
|
||||
|
||||
@@ -76,7 +76,7 @@ The passkey plugin implementation is powered by [SimpleWebAuthn](https://simplew
|
||||
import { createAuthClient } from "better-auth/client"
|
||||
import { passkeyClient } from "better-auth/client/plugins"
|
||||
|
||||
const authClient = createAuthClient({
|
||||
export const authClient = createAuthClient({
|
||||
plugins: [ // [!code highlight]
|
||||
passkeyClient() // [!code highlight]
|
||||
] // [!code highlight]
|
||||
|
||||
@@ -15,7 +15,7 @@ The username plugin wraps the email and password authenticator and adds username
|
||||
import { betterAuth } from "better-auth"
|
||||
import { username } from "better-auth/plugins"
|
||||
|
||||
const auth = betterAuth({
|
||||
export const auth = betterAuth({
|
||||
plugins: [ // [!code highlight]
|
||||
username() // [!code highlight]
|
||||
] // [!code highlight]
|
||||
@@ -48,7 +48,7 @@ The username plugin wraps the email and password authenticator and adds username
|
||||
import { createAuthClient } from "better-auth/client"
|
||||
import { usernameClient } from "better-auth/client/plugins"
|
||||
|
||||
const authClient = createAuthClient({
|
||||
export const authClient = createAuthClient({
|
||||
plugins: [ // [!code highlight]
|
||||
usernameClient() // [!code highlight]
|
||||
] // [!code highlight]
|
||||
|
||||
Reference in New Issue
Block a user