docs: started

This commit is contained in:
Bereket Engida
2024-10-31 18:36:12 +03:00
parent 0c3e5c295f
commit e82c858770
4 changed files with 74 additions and 12 deletions

View File

@@ -355,8 +355,7 @@ Better Auth supports any backend framework with standard Request and Response ob
```
</Tab>
<Tab value="tanstack-start">
```ts
// app/routes/api/auth/$.ts
```ts title="app/routes/api/auth/$.ts"
import { auth } from '~/lib/server/auth'
import { createAPIFileRoute } from '@tanstack/start/api'

View File

@@ -3,19 +3,58 @@ title: Expo
description: Learn how to use Better Auth with Expo.
---
Expo is a popular framework for building cross-platform apps with React Native. This guide will show you how to use Better Auth with Expo.
Expo is a popular framework for building cross-platform apps with React Native. Better Auth supports both Expo native and web apps.
## Installation
First we need to install Better Auth main packge on both Expo and Our Server.
<Steps>
<Step>
## Configure A Better Auth Backend
Before using Better Auth with Expo, make sure you have a Better Auth backend set up. You can either use a separate server or leverage Expo's new [API Routes](https://docs.expo.dev/router/reference/api-routes) feature to host your Better Auth instance.
To get started, check out our [installation](/docs/installation) guide for setting up Better Auth on your server.
</Step>
<Step>
## Install Better Auth and Expo Plugin
With your server up and running, install both Better Auth and the Expo plugin in your Expo project.
```package-install
better-auth @better-auth/expo
```
</Step>
<Step>
## Initialize Better Auth Client
To initialize Better Auth in your Expo app, you need to call `createAuthClient` with the base url of your Better Auth backend. Make sure to import the client from `/react`.
```ts title="src/auth-client.ts"
import { createAuthClient } from 'better-auth/react';
const authClient = createAuthClient({
basURL: 'http://localhost:8081', /* base url of your Better Auth backend. */
});
```
<Callout>
Be sure to include the full URL, including the path, if you've changed the default path from `/api/auth`.
</Callout>
</Step>
<Step>
## Configure Metro Bundler
To resolve better auth exports you'll need to enable `unstable_enablePackageExports` in your metro config.
```js title="metro.config.js"
const { getDefaultConfig } = require("expo/metro-config");
const config = getDefaultConfig(__dirname)
config.resolver.unstable_enablePackageExports = true; // [!code highlight]
module.exports = config;
```
</Step>
</Steps>
```package-install
install better-auth
```
Then we need to install the Expo plugin.
```package-install
install @betterauth/expo
```