From dd0cc21a6a1a3508446268564c761bb7e1df9ebc Mon Sep 17 00:00:00 2001 From: Bereket Engida Date: Wed, 5 Mar 2025 00:06:02 +0300 Subject: [PATCH] chore: upgrade Shiki to v1.29.2 and update documentation --- demo/nextjs/package.json | 1 + docs/content/docs/concepts/api.mdx | 56 ++++++++++++++++++++++---- docs/content/docs/concepts/cli.mdx | 54 ++++++++++++------------- docs/content/docs/concepts/client.mdx | 1 - docs/content/docs/concepts/cookies.mdx | 2 +- pnpm-lock.yaml | 9 +++-- 6 files changed, 81 insertions(+), 42 deletions(-) diff --git a/demo/nextjs/package.json b/demo/nextjs/package.json index 286fd9481d..3c827959e6 100644 --- a/demo/nextjs/package.json +++ b/demo/nextjs/package.json @@ -81,6 +81,7 @@ "recharts": "^2.14.1", "resend": "^4.0.1", "server-only": "^0.0.1", + "shiki": "^1.24.0", "sonner": "^1.7.0", "tailwind-merge": "^2.5.5", "tailwindcss-animate": "^1.0.7", diff --git a/docs/content/docs/concepts/api.mdx b/docs/content/docs/concepts/api.mdx index cd5fb248d8..4991e63935 100644 --- a/docs/content/docs/concepts/api.mdx +++ b/docs/content/docs/concepts/api.mdx @@ -3,9 +3,9 @@ title: API description: Better Auth API. --- -When you create a new Better Auth instance, it gives you an `api` object. This object provides functions to interact with the server while your code is running server-side. You can use these functions to call any API endpoint on the server. +When you create a new Better Auth instance, it provides you with an `api` object. This object exposes every endpoint that exist in your better auth instance. And you can use this to interact with Better Auth server side. -Any endpoint added to Better Auth, whether from plugins or the core, will be accessible through the `api` object. +Any endpoint added to Better Auth, whether from plugins or the core, will be accessible through the `api` object. ## Calling API Endpoints on the Server @@ -21,18 +21,30 @@ export const auth = betterAuth({ // calling get session on the server await auth.api.getSession({ - headers: headers() + headers: headers() //some endpoint might require headers }) ``` -Unlike the client, the server needs the values to be passed as an object with the key `body` for the body, `headers` for the headers, and `query` for the query. +### Body, Headers, Query +Unlike the client, the server needs the values to be passed as an object with the key `body` for the body, `headers` for the headers, and `query` for query parameters. ```ts title="server.ts" +await auth.api.getSession({ + headers: headers() +}) + await auth.api.signInEmail({ body: { - email: "", - password: "" + email: "john@doe.com", + password: "password" + }, + headers: headers() // optional but would be useful to get the user IP, user agent, etc. +}) + +await auth.api.verifyEmail({ + query: { + token: "my_token" } }) ``` @@ -41,9 +53,37 @@ await auth.api.signInEmail({ Better auth API endpoints are built on top of [better-call](https://github.com/bekacru/better-call), a tiny web framework that lets you call REST API endpoints as if they were regular functions and allows us to easily infer client types from the server. -### Getting the `Response` Object +### Getting `headers` and `Response` Object -When you invoke an API endpoint on the server, it will return a standard JavaScript object or array directly. To get the `Response` object instead, you can use the `asResponse` option. +When you invoke an API endpoint on the server, it will return a standard JavaScript object or array directly as it's just a regular function call. + +But there are times where you might want to get the `headers` or the `Response` object instead. For example, if you need to get the cookies or the headers. + +#### Getting `headers` + +To get the `headers`, you can pass the `returnHeaders` option to the endpoint. + +```ts +const { headers, response } = await auth.api.signUpEmail({ + returnHeaders: true, + body: { + email: "john@doe.com", + password: "password", + name: "John Doe", + }, +}); +``` + +The `headers` will be a `Headers` object. Which you can use to get the cookies or the headers. + +```ts +const cookies = headers.get("set-cookie"); +const headers = headers.get("x-custom-header"); +``` + +#### Getting `Response` Object + +To get the `Response` object, you can pass the `asResponse` option to the endpoint. ```ts title="server.ts" const response = await auth.api.signInEmail({ diff --git a/docs/content/docs/concepts/cli.mdx b/docs/content/docs/concepts/cli.mdx index 63ea462c66..adccd5a454 100644 --- a/docs/content/docs/concepts/cli.mdx +++ b/docs/content/docs/concepts/cli.mdx @@ -3,25 +3,7 @@ title: CLI description: Built in CLI for managing your project. --- -Better Auth comes with a built-in CLI to help you manage the database schemas or even create new applications with Better Auth! - - -## Init - -The `init` command allows you to initialize Better Auth in your project. - -```bash title="Terminal" -npx @better-auth/cli@latest init -``` - -### Options - -- `--name` - The name of your application. (Defaults to your `package.json`'s `name` property.) -- `--framework` - The framework your codebase is using. Currently, the only supported framework is `nextjs`. -- `--plugins` - The plugins you want to use. You can specify multiple plugins by separating them with a comma. -- `--database` - The database you want to use. Currently, the only supported database is `sqlite`. -- `--package-manager` - The package manager you want to use. Currently, the only supported package managers are `npm`, `pnpm`, `yarn`, `bun`. (Defaults to the manager you used to initialize the CLI.) - +Better Auth comes with a built-in CLI to help you manage the database schemas, initialize your project, and generate a secret key for your application. ## Generate @@ -40,7 +22,7 @@ npx @better-auth/cli@latest generate ## Migrate -The migrate command applies the Better Auth schema directly to your database. This is available if you’re using the built-in Kysely adapter. +The migrate command applies the Better Auth schema directly to your database. This is available if you’re using the built-in Kysely adapter. For other adapters, you'll need to apply the schema using your ORM's migration tool. ```bash title="Terminal" npx @better-auth/cli@latest migrate @@ -51,6 +33,29 @@ npx @better-auth/cli@latest migrate - `--config` - The path to your Better Auth config file. By default, the CLI will search for a auth.ts file in **./**, **./utils**, **./lib**, or any of these directories under `src` directory. - `--y` - Skip the confirmation prompt and apply the schema directly. +## Init + +The `init` command allows you to initialize Better Auth in your project. + +```bash title="Terminal" +npx @better-auth/cli@latest init +``` + +### Options + +- `--name` - The name of your application. (Defaults to your `package.json`'s `name` property.) +- `--framework` - The framework your codebase is using. Currently, the only supported framework is `nextjs`. +- `--plugins` - The plugins you want to use. You can specify multiple plugins by separating them with a comma. +- `--database` - The database you want to use. Currently, the only supported database is `sqlite`. +- `--package-manager` - The package manager you want to use. Currently, the only supported package managers are `npm`, `pnpm`, `yarn`, `bun`. (Defaults to the manager you used to initialize the CLI.) + +## Secret + +The CLI also provides a way to generate a secret key for your Better Auth instance. + +```bash title="Terminal" +npx @better-auth/cli@latest secret +``` ## Common Issues @@ -59,12 +64,3 @@ npx @better-auth/cli@latest migrate If you see this error, it means the CLI can’t resolve imported modules in your Better Auth config file. We're working on a fix for many of these issues, but in the meantime, you can try the following: - Remove any import aliases in your config file and use relative paths instead. After running the CLI, you can revert to using aliases. - - -## Secret - -The CLI also provides a way to generate a secret key for your Better Auth instance. - -```bash title="Terminal" -npx @better-auth/cli@latest secret -``` \ No newline at end of file diff --git a/docs/content/docs/concepts/client.mdx b/docs/content/docs/concepts/client.mdx index cc97df8bb4..207988858b 100644 --- a/docs/content/docs/concepts/client.mdx +++ b/docs/content/docs/concepts/client.mdx @@ -86,7 +86,6 @@ await authClient.signIn.email({ On top of normal methods, the client provides hooks to easily access different reactive data. Every hook is available in the root object of the client and they all start with `use`. - **Example: useSession** diff --git a/docs/content/docs/concepts/cookies.mdx b/docs/content/docs/concepts/cookies.mdx index 52eecdd68a..a188fca73e 100644 --- a/docs/content/docs/concepts/cookies.mdx +++ b/docs/content/docs/concepts/cookies.mdx @@ -96,4 +96,4 @@ export const auth = betterAuth({ useSecureCookies: true } }) -``` +``` \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 76f85a0300..155eb6dc2e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -273,6 +273,9 @@ importers: server-only: specifier: ^0.0.1 version: 0.0.1 + shiki: + specifier: ^1.24.0 + version: 1.29.2 sonner: specifier: ^1.7.0 version: 1.7.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0) @@ -20806,7 +20809,7 @@ snapshots: remark-parse: 11.0.0 remark-rehype: 11.1.1 remark-smartypants: 3.0.2 - shiki: 1.24.0 + shiki: 1.29.2 unified: 11.0.4 unist-util-remove-position: 5.0.0 unist-util-visit: 5.0.0 @@ -32173,7 +32176,7 @@ snapshots: prompts: 2.4.2 rehype: 13.0.2 semver: 7.6.3 - shiki: 1.24.0 + shiki: 1.29.2 tinyexec: 0.3.1 tsconfck: 3.1.4(typescript@5.7.2) unist-util-visit: 5.0.0 @@ -42597,7 +42600,7 @@ snapshots: rehype-stringify@10.0.1: dependencies: '@types/hast': 3.0.4 - hast-util-to-html: 9.0.3 + hast-util-to-html: 9.0.5 unified: 11.0.4 rehype@13.0.2: