diff --git a/docs/content/docs/concepts/email.mdx b/docs/content/docs/concepts/email.mdx index 469d7f70d2..83cd63fb1d 100644 --- a/docs/content/docs/concepts/email.mdx +++ b/docs/content/docs/concepts/email.mdx @@ -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 } diff --git a/docs/content/docs/concepts/rate-limit.mdx b/docs/content/docs/concepts/rate-limit.mdx index 2d887b04e9..9e038eec2b 100644 --- a/docs/content/docs/concepts/rate-limit.mdx +++ b/docs/content/docs/concepts/rate-limit.mdx @@ -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: { diff --git a/docs/content/docs/concepts/session-management.mdx b/docs/content/docs/concepts/session-management.mdx index b82c5d902c..cde0957c32 100644 --- a/docs/content/docs/concepts/session-management.mdx +++ b/docs/content/docs/concepts/session-management.mdx @@ -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()], }); -const { data } = await authClient.useSession(); +const { data } = authClient.useSession(); const { data: sessionData } = await authClient.getSession(); // data.roles // data.user.newField diff --git a/docs/content/docs/plugins/2fa.mdx b/docs/content/docs/plugins/2fa.mdx index 42e31b89c5..d69a58a3a8 100644 --- a/docs/content/docs/plugins/2fa.mdx +++ b/docs/content/docs/plugins/2fa.mdx @@ -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() ] diff --git a/docs/content/docs/plugins/anonymous.mdx b/docs/content/docs/plugins/anonymous.mdx index 1f725c3b00..23c3ca03c2 100644 --- a/docs/content/docs/plugins/anonymous.mdx +++ b/docs/content/docs/plugins/anonymous.mdx @@ -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() ] diff --git a/docs/content/docs/plugins/api-key.mdx b/docs/content/docs/plugins/api-key.mdx index b3573654b1..8f5069abe7 100644 --- a/docs/content/docs/plugins/api-key.mdx +++ b/docs/content/docs/plugins/api-key.mdx @@ -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] diff --git a/docs/content/docs/plugins/captcha.mdx b/docs/content/docs/plugins/captcha.mdx index 1eec21bcd5..4c98a191dc 100644 --- a/docs/content/docs/plugins/captcha.mdx +++ b/docs/content/docs/plugins/captcha.mdx @@ -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] }); ``` diff --git a/docs/content/docs/plugins/email-otp.mdx b/docs/content/docs/plugins/email-otp.mdx index b3bc957b98..20c4ac12df 100644 --- a/docs/content/docs/plugins/email-otp.mdx +++ b/docs/content/docs/plugins/email-otp.mdx @@ -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() ] diff --git a/docs/content/docs/plugins/generic-oauth.mdx b/docs/content/docs/plugins/generic-oauth.mdx index 5647902a73..9e07e342df 100644 --- a/docs/content/docs/plugins/generic-oauth.mdx +++ b/docs/content/docs/plugins/generic-oauth.mdx @@ -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() ] diff --git a/docs/content/docs/plugins/magic-link.mdx b/docs/content/docs/plugins/magic-link.mdx index 3ff8e2f378..9995045b24 100644 --- a/docs/content/docs/plugins/magic-link.mdx +++ b/docs/content/docs/plugins/magic-link.mdx @@ -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() ] diff --git a/docs/content/docs/plugins/multi-session.mdx b/docs/content/docs/plugins/multi-session.mdx index 994aa32066..349d1b9a0c 100644 --- a/docs/content/docs/plugins/multi-session.mdx +++ b/docs/content/docs/plugins/multi-session.mdx @@ -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() ] diff --git a/docs/content/docs/plugins/one-tap.mdx b/docs/content/docs/plugins/one-tap.mdx index 89620370d5..abecc98c18 100644 --- a/docs/content/docs/plugins/one-tap.mdx +++ b/docs/content/docs/plugins/one-tap.mdx @@ -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 diff --git a/docs/content/docs/plugins/organization.mdx b/docs/content/docs/plugins/organization.mdx index 2c027f9adf..9684653608 100644 --- a/docs/content/docs/plugins/organization.mdx +++ b/docs/content/docs/plugins/organization.mdx @@ -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] diff --git a/docs/content/docs/plugins/passkey.mdx b/docs/content/docs/plugins/passkey.mdx index 73e5034431..5f812c02e3 100644 --- a/docs/content/docs/plugins/passkey.mdx +++ b/docs/content/docs/plugins/passkey.mdx @@ -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] diff --git a/docs/content/docs/plugins/username.mdx b/docs/content/docs/plugins/username.mdx index 42fd02f3b4..f1c2d71b6e 100644 --- a/docs/content/docs/plugins/username.mdx +++ b/docs/content/docs/plugins/username.mdx @@ -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]