mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-09 20:27:44 +00:00
docs(expo): remove $fetch api usage
This commit is contained in:
@@ -317,33 +317,7 @@ On native, the session data will be cached in SecureStore. This will allow you t
|
||||
|
||||
### Making Authenticated Requests to Your Server
|
||||
|
||||
To make authenticated requests to your server that require the user's session, you have two options:
|
||||
|
||||
1. Use the fetch client provided by Better Auth.
|
||||
2. Retrieve the session cookie from `SecureStore` and manually add it to your request headers.
|
||||
|
||||
---
|
||||
|
||||
#### Option 1: Using the Fetch Client
|
||||
|
||||
Better Auth provides a built-in fetch client powered by [Better Fetch](http://better-fetch.vercel.app). This client automatically includes the session cookie in the headers of your requests.
|
||||
|
||||
```tsx
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
|
||||
const $fetch = authClient.$fetch;
|
||||
|
||||
// Example usage
|
||||
$fetch("/api/secure-endpoint", {
|
||||
method: "GET",
|
||||
});
|
||||
```
|
||||
|
||||
For more details, see the [Better Fetch documentation](http://better-fetch.vercel.app/docs).
|
||||
|
||||
#### Option 2: Adding the Cookie to Request Headers
|
||||
|
||||
If you prefer using your own fetch client, you can retrieve the session cookie stored in the device using `authClient.getCookie` and manually add it to your request headers.
|
||||
To make authenticated requests to your server that require the user's session, you have to retrieve the session cookie from `SecureStore` and manually add it to your request headers.
|
||||
|
||||
```tsx
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
|
||||
Reference in New Issue
Block a user