mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 23:29:08 +03:00
Partials are currently defined via MDX includes. This PR switches to pre-compile-time partials, which have a new syntax: ``` <$Partial path="path/to/file.mdx" /> ``` ## Rationale This produces two improvements: 1. Partial substitution can occur in pipelines that don't use MDX compilation. For example, we can now do partial substitution before building the search index, so partial content will also be indexed. 2. After the App Router migration, the MDXProviders should've been deprecated, but were kept around for the sole reason of making partials work, and leading to us shipping unnecessary client-side code. We get a minor decrease in overall client bundle size (5.74 MB to 5.6 MB) by getting rid of the Providers. ## Breaking changes Besides the change to partial syntax, the arguments are also less powerful than before because we are doing string substitution and don't have the full power of JS. Defining string variables is still possible (documented in the Contributing guide), and since that's all we actually do in practice, this shouldn't be too cumbersome. There is always the escape hatch of making a custom component for more complex content reuse cases.
224 lines
7.3 KiB
Plaintext
224 lines
7.3 KiB
Plaintext
---
|
|
title: 'Use Supabase with refine'
|
|
subtitle: 'Learn how to create a Supabase project, add some sample data to your database, and query the data from a refine app.'
|
|
breadcrumb: 'Framework Quickstarts'
|
|
hideToc: true
|
|
---
|
|
|
|
<StepHikeCompact>
|
|
|
|
<StepHikeCompact.Step step={1}>
|
|
|
|
<$Partial path="quickstart_db_setup.mdx" />
|
|
|
|
</StepHikeCompact.Step>
|
|
|
|
<StepHikeCompact.Step step={2}>
|
|
|
|
<StepHikeCompact.Details title="Create a refine app">
|
|
|
|
Create a [refine](https://github.com/refinedev/refine) app using the [create refine-app](https://refine.dev/docs/getting-started/quickstart/).
|
|
|
|
The `refine-supabase` preset adds `@refinedev/supabase` supplementary package that supports Supabase in a refine app. `@refinedev/supabase` out-of-the-box includes the Supabase dependency: [supabase-js](https://github.com/supabase/supabase-js).
|
|
|
|
</StepHikeCompact.Details>
|
|
|
|
<StepHikeCompact.Code>
|
|
|
|
```bash Terminal
|
|
npm create refine-app@latest -- --preset refine-supabase my-app
|
|
```
|
|
|
|
</StepHikeCompact.Code>
|
|
|
|
</StepHikeCompact.Step>
|
|
|
|
<StepHikeCompact.Step step={3}>
|
|
<StepHikeCompact.Details title="Open your refine app in VS Code">
|
|
|
|
You will develop your app, connect to the Supabase backend and run the refine app in VS Code.
|
|
|
|
</StepHikeCompact.Details>
|
|
|
|
<StepHikeCompact.Code>
|
|
|
|
```bash Terminal
|
|
cd my-app
|
|
code .
|
|
```
|
|
|
|
</StepHikeCompact.Code>
|
|
|
|
</StepHikeCompact.Step>
|
|
|
|
<StepHikeCompact.Step step={4}>
|
|
<StepHikeCompact.Details title="Start the app">
|
|
|
|
Start the app, go to http://localhost:5173 in a browser, and you should be greeted with the refine Welcome page.
|
|
|
|
</StepHikeCompact.Details>
|
|
|
|
<StepHikeCompact.Code>
|
|
|
|
```bash Terminal
|
|
npm run dev
|
|
```
|
|
|
|
<StepHikeCompact.Code>
|
|

|
|
</StepHikeCompact.Code>
|
|
|
|
</StepHikeCompact.Code>
|
|
|
|
</StepHikeCompact.Step>
|
|
|
|
<StepHikeCompact.Step step={5}>
|
|
<StepHikeCompact.Details title="Update `supabaseClient`">
|
|
|
|
You now have to update the `supabaseClient` with the `SUPABASE_URL` and `SUPABASE_KEY` of your Supabase API. The `supabaseClient` is used in auth provider and data provider methods that allow the refine app to connect to your Supabase backend.
|
|
|
|
<ProjectConfigVariables variable="url" />
|
|
<ProjectConfigVariables variable="anonKey" />
|
|
|
|
</StepHikeCompact.Details>
|
|
|
|
<StepHikeCompact.Code>
|
|
|
|
```ts src/utility/supabaseClient.ts
|
|
import { createClient } from "@refinedev/supabase";
|
|
|
|
const SUPABASE_URL = YOUR_SUPABASE_URL;
|
|
const SUPABASE_KEY = YOUR_SUPABASE_KEY
|
|
|
|
export const supabaseClient = createClient(SUPABASE_URL, SUPABASE_KEY, {
|
|
db: {
|
|
schema: "public",
|
|
},
|
|
auth: {
|
|
persistSession: true,
|
|
},
|
|
});
|
|
```
|
|
|
|
</StepHikeCompact.Code>
|
|
|
|
</StepHikeCompact.Step>
|
|
|
|
<StepHikeCompact.Step step={6}>
|
|
<StepHikeCompact.Details title="Add instruments resource and pages">
|
|
|
|
You have to then configure resources and define pages for `instruments` resource.
|
|
|
|
Use the following command to automatically add resources and generate code for pages for `instruments` using refine Inferencer.
|
|
|
|
This defines pages for `list`, `create`, `show` and `edit` actions inside the `src/pages/instruments/` directory with `<HeadlessInferencer />` component.
|
|
|
|
The `<HeadlessInferencer />` component depends on `@refinedev/react-table` and `@refinedev/react-hook-form` packages. In order to avoid errors, you should install them as dependencies with `npm install @refinedev/react-table @refinedev/react-hook-form`.
|
|
|
|
<Admonition type="note">
|
|
|
|
The `<HeadlessInferencer />` is a refine Inferencer component that automatically generates necessary code for the `list`, `create`, `show` and `edit` pages.
|
|
|
|
More on [how the Inferencer works is available in the docs here](https://refine.dev/docs/packages/documentation/inferencer/).
|
|
|
|
</Admonition>
|
|
|
|
|
|
</StepHikeCompact.Details>
|
|
|
|
<StepHikeCompact.Code>
|
|
|
|
```bash Terminal
|
|
npm run refine create-resource instruments
|
|
```
|
|
</StepHikeCompact.Code>
|
|
|
|
</StepHikeCompact.Step>
|
|
|
|
<StepHikeCompact.Step step={7}>
|
|
<StepHikeCompact.Details title="Add routes for instruments pages">
|
|
|
|
Add routes for the `list`, `create`, `show`, and `edit` pages.
|
|
|
|
<Admonition type="tip">
|
|
|
|
You should remove the `index` route for the Welcome page presented with the `<Welcome />` component.
|
|
|
|
</Admonition>
|
|
|
|
</StepHikeCompact.Details>
|
|
|
|
<StepHikeCompact.Code>
|
|
```tsx src/App.tsx
|
|
import { Refine, WelcomePage } from "@refinedev/core";
|
|
import { RefineKbar, RefineKbarProvider } from "@refinedev/kbar";
|
|
import routerBindings, {
|
|
DocumentTitleHandler,
|
|
NavigateToResource,
|
|
UnsavedChangesNotifier,
|
|
} from "@refinedev/react-router-v6";
|
|
import { dataProvider, liveProvider } from "@refinedev/supabase";
|
|
import { BrowserRouter, Route, Routes } from "react-router-dom";
|
|
|
|
import "./App.css";
|
|
import authProvider from "./authProvider";
|
|
import { supabaseClient } from "./utility";
|
|
import { InstrumentsCreate, InstrumentsEdit, InstrumentsList, InstrumentsShow } from "./pages/instruments";
|
|
|
|
function App() {
|
|
return (
|
|
<BrowserRouter>
|
|
<RefineKbarProvider>
|
|
<Refine
|
|
dataProvider={dataProvider(supabaseClient)}
|
|
liveProvider={liveProvider(supabaseClient)}
|
|
authProvider={authProvider}
|
|
routerProvider={routerBindings}
|
|
options={{
|
|
syncWithLocation: true,
|
|
warnWhenUnsavedChanges: true,
|
|
}}
|
|
resources={[{
|
|
name: "instruments",
|
|
list: "/instruments",
|
|
create: "/instruments/create",
|
|
edit: "/instruments/edit/:id",
|
|
show: "/instruments/show/:id"
|
|
}]}>
|
|
<Routes>
|
|
<Route index
|
|
element={<NavigateToResource resource="instruments" />}
|
|
/>
|
|
<Route path="/instruments">
|
|
<Route index element={<InstrumentsList />} />
|
|
<Route path="create" element={<InstrumentsCreate />} />
|
|
<Route path="edit/:id" element={<InstrumentsEdit />} />
|
|
<Route path="show/:id" element={<InstrumentsShow />} />
|
|
</Route>
|
|
</Routes>
|
|
<RefineKbar />
|
|
<UnsavedChangesNotifier />
|
|
<DocumentTitleHandler />
|
|
</Refine>
|
|
</RefineKbarProvider>
|
|
</BrowserRouter>
|
|
);
|
|
}
|
|
|
|
export default App;
|
|
```
|
|
</StepHikeCompact.Code>
|
|
|
|
</StepHikeCompact.Step>
|
|
|
|
<StepHikeCompact.Step step={8}>
|
|
<StepHikeCompact.Details title="View instruments pages">
|
|
|
|
Now you should be able to see the instruments pages along the `/instruments` routes. You may now edit and add new instruments using the Inferencer generated UI.
|
|
|
|
The Inferencer auto-generated code gives you a good starting point on which to keep building your `list`, `create`, `show` and `edit` pages. They can be obtained by clicking the `Show the auto-generated code` buttons in their respective pages.
|
|
</StepHikeCompact.Details>
|
|
|
|
</StepHikeCompact.Step>
|
|
</StepHikeCompact>
|