mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-10 04:19:32 +00:00
chore: upgrade Shiki to v1.29.2 and update documentation
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -3,7 +3,7 @@ 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.
|
||||
|
||||
@@ -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.
|
||||
</Callout>
|
||||
|
||||
### 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({
|
||||
|
||||
@@ -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,15 +33,21 @@ 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
|
||||
|
||||
## Common Issues
|
||||
The `init` command allows you to initialize Better Auth in your project.
|
||||
|
||||
**Error: Cannot find module X**
|
||||
```bash title="Terminal"
|
||||
npx @better-auth/cli@latest init
|
||||
```
|
||||
|
||||
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.
|
||||
### 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
|
||||
|
||||
@@ -68,3 +56,11 @@ The CLI also provides a way to generate a secret key for your Better Auth instan
|
||||
```bash title="Terminal"
|
||||
npx @better-auth/cli@latest secret
|
||||
```
|
||||
|
||||
## Common Issues
|
||||
|
||||
**Error: Cannot find module X**
|
||||
|
||||
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.
|
||||
|
||||
@@ -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**
|
||||
|
||||
|
||||
|
||||
9
pnpm-lock.yaml
generated
9
pnpm-lock.yaml
generated
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user