Skip to content

Latest commit

 

History

History
85 lines (60 loc) · 3.75 KB

File metadata and controls

85 lines (60 loc) · 3.75 KB

🏡 Home

Create Supabase project Create Remix application Query Supabase data with Remix Loaders Generate TypeScript types from Supabase CLI Implement Supabase Auth using GitHub Restrict access with RLS policies Automatically set session cookie with Supabase Auth Helpers Call active Loaders on Supabase Auth state change Mutate Supabase data with Remix Actions Subscribe to database changes with Supabase Realtime Deploy Remix app to Vercel

Query Supabase data with Remix Loaders

📹 Video

The supabase-js package allows us to connect to our Supabase project, and easily query and mutate data. In this lesson, we install supabase-js, set up environment variables for SUPABASE_URL and SUPABASE_ANON_KEY, and create a Supabase client to use across our application.

Additionally, we look at writing an RLS policy to enable read access to our messages table, use our Supabase client to select all messages, and display them in our Remix app on load.

Code Snippets

Install supabase-js

npm i @supabase/supabase-js

Use a Loader function to fetch data

export const loader = async () => {
  return null;
};

Fetch data with Supabase Client

const { data } = await supabase.from("messages").select();

Full component

import { useLoaderData } from "@remix-run/react";
import supabase from "utils/supabase";

export const loader = async ({}) => {
  const { data } = await supabase.from("messages").select();
  return { data };
};

export default function Index() {
  const { data } = useLoaderData();
  return <pre>{JSON.stringify(data, null, 2)}</pre>;
}

Enable read access with RLS policy

create policy "users can read messages" ON "public"."messages"
as permissive for select
to public
using (true);

SQL code snippets can be run against your Supabase database by heading over to your project's SQL Editor, pasting them into a new query, and clicking RUN.

Resources


👉 Next lesson


Enjoying the course? Follow Jon Meyers on Twitter and subscribe to the YouTube channel.