docs/pages/guides/using-supabase.mdx
import { BoxLink } from '/ui/components/BoxLink';
import { Terminal } from '/ui/components/Snippet';
import { Step } from '~/ui/components/Step';
Supabase is a Backend-as-a-Service (BaaS) app development platform that provides hosted backend services such as a Postgres database, user authentication, file storage, edge functions, realtime syncing, and a vector and AI toolkit. It's an open-source alternative to Google's Firebase.
Supabase automatically generates a REST API from your database and employs a concept called row level security (RLS) to secure your data, making it possible to directly interact with your database from your React Native application without needing to go through a server!
Supabase provides a TypeScript client library called supabase-js to interact with the REST API. Alternatively, Supabase also exposes a GraphQL API allowing you to use your favorite GraphQL client (for example, Apollo Client) should you wish to.
Head over to database.new to create a new Supabase project.
Get the Project URL from the API settings and Publishable key from the API Keys:
URL and service_role keys on this page.Using supabase-js is the most convenient way of leveraging the full power of the Supabase stack as it conveniently combines all the different services (database, auth, realtime, storage, edge functions) together.
After you have created your Expo project, install @supabase/supabase-js and the required dependencies using the following command:
<Terminal cmd={['$ npx expo install @supabase/supabase-js expo-sqlite']} /> </Step>
<Step label="2">Create a helper file to initialize the Supabase client (@supabase/supabase-js). You need the API URL and the Publishable key copied earlier. These variables are safe to expose in your Expo app since Supabase has Row Level Security enabled in the Database.
import 'expo-sqlite/localStorage/install';
import { createClient } from '@supabase/supabase-js';
const supabaseUrl = YOUR_REACT_NATIVE_SUPABASE_URL;
const supabasePublishableKey = YOUR_REACT_NATIVE_SUPABASE_PUBLISHABLE_KEY;
export const supabase = createClient(supabaseUrl, supabasePublishableKey, {
auth: {
storage: localStorage,
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: false,
},
});
Now you can import { supabase } from '/utils/supabase' throughout your application to leverage the full power of Supabase!
<BoxLink title="Build a User Management App" description="Learn how to combine Supabase Auth and Database in this quickstart guide." href="https://supabase.com/docs/guides/getting-started/tutorials/with-expo-react-native?utm_source=expo&utm_medium=referral&utm_term=expo-react-native" />
<BoxLink title="Sign in with Apple" description="Supabase Auth supports using Sign in with Apple on the web and in native apps for iOS, macOS, watchOS or tvOS." href="https://supabase.com/docs/guides/auth/social-login/auth-apple?platform=react-native&utm_source=expo&utm_medium=referral&utm_term=expo-react-native" />
<BoxLink title="Sign in with Google" description="Supabase Auth supports Sign in with Google on the web, native Android applications, and Chrome extensions." href="https://supabase.com/docs/guides/auth/social-login/auth-google?platform=react-native&utm_source=expo&utm_medium=referral&utm_term=expo-react-native" />
<BoxLink title="Deep Linking for OAuth and Magic Links" description="When performing OAuth or sending magic link emails from native mobile applications, learn how to configure deep linking for Android and iOS applications." href="https://supabase.com/docs/guides/auth/native-mobile-deep-linking?utm_source=expo&utm_medium=referral&utm_term=expo-react-native" />
<BoxLink title="Offline-first React Native Apps with WatermelonDB" description="Learn how to store your data locally and sync it with Postgres using WatermelonDB." href="https://supabase.com/blog/react-native-offline-first-watermelon-db?utm_source=expo&utm_medium=referral&utm_term=expo-react-native" />
<BoxLink title="React Native file upload with Supabase Storage" description="Learn how to implement authentication and file upload in a React Native app." href="https://supabase.com/blog/react-native-storage?utm_source=expo&utm_medium=referral&utm_term=expo-react-native" />