mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 04:19:20 +00:00
docs: fix typo
This commit is contained in:
BIN
banner-dark.png
BIN
banner-dark.png
Binary file not shown.
|
Before Width: | Height: | Size: 851 KiB After Width: | Height: | Size: 820 KiB |
BIN
banner.png
BIN
banner.png
Binary file not shown.
|
Before Width: | Height: | Size: 659 KiB After Width: | Height: | Size: 617 KiB |
@@ -190,16 +190,14 @@ If you throw an `APIError` from the middleware or returned a `Response` object,
|
||||
|
||||
Additional to middlewares you can also hook into right before a request is made and right after a response is returned. This is mostly useful if you wnat to do something that affects all requests or responses.
|
||||
|
||||
### On Request
|
||||
#### On Request
|
||||
|
||||
The `onRequest` function is called right before the request is made. It takes two parameters: the `request` and the `context` object.
|
||||
|
||||
Here’s how it works:
|
||||
|
||||
- **Continue as Normal**: If you don't return anything, the request will proceed as usual.
|
||||
|
||||
- **Interrupt the Request**: To stop the request and send a response, return an object with a `response` property that contains a `Response` object.
|
||||
|
||||
- **Modify the Request**: You can also return a modified `request` object to change the request before it's sent.
|
||||
|
||||
```ts title="plugin.ts"
|
||||
@@ -211,14 +209,13 @@ const myPlugin = {
|
||||
}
|
||||
```
|
||||
|
||||
### On Response
|
||||
#### On Response
|
||||
|
||||
The `onResponse` function is executed immediately after a response is returned. It takes two parameters: the `response` and the `context` object.
|
||||
|
||||
Here’s how to use it:
|
||||
|
||||
- **Modify the Response**: You can return a modified response object to change the response before it is sent to the client.
|
||||
|
||||
- **Continue Normally**: If you don’t return anything, the response will be sent as is.
|
||||
|
||||
```ts title="plugin.ts"
|
||||
@@ -268,9 +265,7 @@ const myPlugin = {
|
||||
#### When to use Middelware, Hooks, On Request, On Response
|
||||
|
||||
- **Middlewares**: You should use middlewares when you want to use a route matcher to target a group of routes.
|
||||
|
||||
- **Hooks**: You should use hooks when you want to target a specific route or request.
|
||||
|
||||
- **On Request & On Response**: You should use on request and on response when you want to do something that affects all requests or responses.
|
||||
|
||||
### Rate Limit
|
||||
|
||||
Reference in New Issue
Block a user