@faire-auth/expo
v1.0.0
Published
Faire Auth integration for Expo and React Native applications.
Maintainers
Readme
Faire Auth Expo Plugin
This plugin integrates Faire Auth with Expo, allowing you to easily add authentication to your Expo (React Native) applications. It supports both Expo native and web apps.
Installation
To get started, install the necessary packages:
# Using npm
npm install faire-auth @faire-auth/expo
# Using yarn
yarn add faire-auth @faire-auth/expo
# Using pnpm
pnpm add faire-auth @faire-auth/expo
# Using bun
bun add faire-auth @faire-auth/expoYou will also need to install expo-secure-store for secure session and cookie storage in your Expo app:
npm install expo-secure-store
# or
yarn add expo-secure-store
# or
pnpm add expo-secure-store
# or
bun add expo-secure-storeBasic Usage
Configure the Faire Auth Backend
Ensure you have a Faire Auth backend set up. You can follow the main Installation Guide.
Then, add the Expo plugin to your Faire Auth server configuration (e.g., in your auth.ts or lib/auth.ts file):
// lib/auth.ts
import { faireAuth } from "faire-auth";
import { expo } from "@faire-auth/expo"; // Import the server plugin
export const auth = faireAuth({
// ...your other Faire Auth options
baseURL: "http://localhost:8081", // The base URL of your application server where the routes are mounted.
plugins: [expo()], // Add the Expo server plugin
emailAndPassword: {
enabled: true,
},
// Add other configurations like trustedOrigins
trustedOrigins: ["myapp://"] // Replace "myapp" with your app's scheme
});Initialize the Faire Auth Client in Expo
In your Expo app, initialize the client (e.g., in lib/auth-client.ts):
// lib/auth-client.ts
import { createAuthClient } from "faire-auth/react";
import { expoClient } from "@faire-auth/expo/client"; // Import the client plugin
import * as SecureStore from "expo-secure-store";
export const authClient = createAuthClient({
baseURL: "http://localhost:8081", // Your Faire Auth backend URL
plugins: [
expoClient({
scheme: "myapp", // Your app's scheme (defined in app.json)
storagePrefix: "myapp", // A prefix for storage keys
storage: SecureStore, // Pass SecureStore for token storage
})
]
});
// You can also export specific methods if you prefer:
// export const { signIn, signUp, useSession } = authClient;Make sure your app's scheme (e.g., "myapp") is defined in your app.json.
Documentation
For more detailed information and advanced configurations, please refer to the documentation:
- Main Faire Auth Installation: https://www.faire-auth.com/docs/installation
- Expo Integration Guide: https://www.faire-auth.com/docs/integrations/expo
License
MIT
