HomeGuidesReferenceLearn
ArchiveExpo SnackDiscord and ForumsNewsletter

Use Supabase

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.

Prerequisites

Head over to database.new to create a new Supabase project.

Get the API Keys

Get the Project URL and anon key from the API settings.

  1. Go to the API Settings page in the Dashboard.
  2. Find your Project URL, anon, and service_role keys on this page.

Using the Supabase TypeScript SDK

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.

Install and initialize the Supabase TypeScript SDK

1

Install supabase-js and dependencies

After you have created your Expo project, you can install supabase-js and the required dependencies using the following command:

Terminal
npx expo install @supabase/supabase-js @react-native-async-storage/async-storage react-native-url-polyfill

2

Initialize supabase-js in your project

Create a helper file to initialize the Supabase client. We need the API URL and the anon key you copied earlier. These variables are safe to expose in your Expo app since Supabase has Row Level Security enabled on our Database.

utils/supabase.ts
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!

Next steps

Build a User Management App

Learn how to combine Supabase Auth and Database in this quickstart guide.

Sign in with Apple

Supabase Auth supports using Sign in with Apple on the web and in native apps for iOS, macOS, watchOS or tvOS.

Sign in with Google

Supabase Auth supports Sign in with Google on the web, native Android applications, and Chrome extensions.

Deep Linking for OAuth and Magic Links

When performing OAuth or sending magic link emails from native mobile applications, learn how to configure deep linking for Android and iOS applications.

Offline-first React Native Apps with WatermelonDB

Learn how to store your data locally and sync it with Postgres using WatermelonDB.

React Native file upload with Supabase Storage

Learn how to implement authentication and file upload in a React Native app.