From 6ad6cded12d4bf424dfe46745d951e1c3fbbfc90 Mon Sep 17 00:00:00 2001 From: Bereket Engida Date: Thu, 31 Oct 2024 23:28:09 +0300 Subject: [PATCH] docs: add expo docs --- docs/components/features.tsx | 5 +- docs/components/icons.tsx | 1 + docs/components/techstack-icons.tsx | 4 + docs/content/docs/installation.mdx | 10 +- docs/content/docs/integrations/expo.mdx | 164 ++++++++++++++++++++++++ packages/expo/src/client.ts | 6 +- 6 files changed, 186 insertions(+), 4 deletions(-) diff --git a/docs/components/features.tsx b/docs/components/features.tsx index d7c81dbbb1..62a96b4ee6 100644 --- a/docs/components/features.tsx +++ b/docs/components/features.tsx @@ -188,8 +188,9 @@ export default function Features({ stars }: { stars: string | null }) { "svelteKit", "astro", "solidStart", - "react", - "hono", + // "react", + // "hono", + "expo", "tanstack", ]} /> diff --git a/docs/components/icons.tsx b/docs/components/icons.tsx index a5504cadb5..ecdcf89b9b 100644 --- a/docs/components/icons.tsx +++ b/docs/components/icons.tsx @@ -398,6 +398,7 @@ export const Icons = { width="1.2em" height="1.2em" viewBox="0 0 32 32" + {...props} > , }, + expo: { + name: "Expo", + icon: , + }, }; diff --git a/docs/content/docs/installation.mdx b/docs/content/docs/installation.mdx index b745bcba45..df02289dea 100644 --- a/docs/content/docs/installation.mdx +++ b/docs/content/docs/installation.mdx @@ -236,7 +236,7 @@ Create a new file or route in your framework's designated catch-all route handle Better Auth supports any backend framework with standard Request and Response objects and offers helper functions for popular frameworks. - + ```ts title="/app/api/auth/[...all]/route.ts" import { auth } from "@/lib/auth"; // path to your auth file @@ -369,6 +369,14 @@ Better Auth supports any backend framework with standard Request and Response ob }); ``` + + ```ts title="app/api/auth/[..all]+api.ts" + import { auth } from '@/lib/server/auth'; // path to your auth file + + const handler = auth.handler; + export { handler as GET, handler as POST }; + ``` + diff --git a/docs/content/docs/integrations/expo.mdx b/docs/content/docs/integrations/expo.mdx index 5138bdfa14..08e850de3c 100644 --- a/docs/content/docs/integrations/expo.mdx +++ b/docs/content/docs/integrations/expo.mdx @@ -13,6 +13,15 @@ Expo is a popular framework for building cross-platform apps with React Native. 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. + + To use the new API routes feature in Expo to host your Better Auth instance you can create a new API route in your Expo app and mount the Better Auth handler. + + ```ts title="app/api/auth/[...auth]+api.ts" + import { auth } from "@/lib/auth"; // import Better Auth handler + + const handler = auth.handler; + export { handler as GET, handler as POST }; // export handler for both GET and POST requests + ``` ## Install Better Auth and Expo Plugin @@ -57,4 +66,159 @@ Expo is a popular framework for building cross-platform apps with React Native. +## Usage +### Authenticating Users + +With Better Auth initialized, you can now use the `authClient` to authenticate users in your Expo app. + + + + ```tsx title="app/sign-in.tsx" + import { useState } from 'react'; + import { View, TextInput, Button } from 'react-native'; + import { authClient } from './auth-client'; + + export default function App() { + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + + const handleLogin = async () => { + await authClient.signIn.email({ + email, + password, + }) + }; + + return ( + + + +