Edit this page
Add a Postgres Database and user authentication to your React Native app with Supabase.
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 and anon
key from the API settings.
URL
, anon
, 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.
1
After you have created your Expo project, install @supabase/supabase-js
and the required dependencies using the following command:
-
npx expo install @supabase/supabase-js @react-native-async-storage/async-storage react-native-url-polyfill
2
Create a helper file to initialize the Supabase client (@supabase/supabase-js
). You need the API URL and the anon
key copied earlier. These variables are safe to expose in your Expo app since Supabase has Row Level Security enabled in the Database.
import 'react-native-url-polyfill/auto';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { createClient } from '@supabase/supabase-js';
const supabaseUrl = YOUR_REACT_NATIVE_SUPABASE_URL;
const supabaseAnonKey = YOUR_REACT_NATIVE_SUPABASE_ANON_KEY;
export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
auth: {
storage: AsyncStorage,
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: false,
},
});
Now you can import { supabase } from '/utils/supabase'
throughout your application to leverage the full power of Supabase!
Learn how to combine Supabase Auth and Database in this quickstart guide.
Supabase Auth supports using Sign in with Apple on the web and in native apps for iOS, macOS, watchOS or tvOS.
Supabase Auth supports Sign in with Google on the web, native Android applications, and Chrome extensions.
When performing OAuth or sending magic link emails from native mobile applications, learn how to configure deep linking for Android and iOS applications.
Learn how to store your data locally and sync it with Postgres using WatermelonDB.
Learn how to implement authentication and file upload in a React Native app.