The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Updates the react guide - about 80% complete now
Paul Copplestone4218b62de7b3
diff --git a/web/docs/guides/with-react.mdx b/web/docs/guides/with-react.mdxindex e47257f4d9c..3212ea84456 100644--- a/web/docs/guides/with-react.mdx+++ b/web/docs/guides/with-react.mdx@@ -7,19 +7,53 @@ description: Learn how to use Supabase in your React App.import Tabs from '@theme/Tabs';import TabItem from '@theme/TabItem';-## Intro-Shows you how to build a simple user management app (from scratch!) using Supabase and React. It includes:-- Supabase Auth: users can sign in with magic links (no passwords, only email).-- Supabase Storage: users can upload a photo.-- Row Level Security: data will be locked so that individuals can only access their own data.+This example provides the steps to build a simple user management app (from scratch!) using Supabase and React. It includes:+- Supabase [Auth](/docs/guides/auth): users can sign in with magic links (no passwords, only email).+- Supabase [Storage](/docs/guides/storage): users can upload a photo.+- [Row Level Security](/docs/guides/auth#row-level-security): data is be protected so that individuals can only access their own data.+- Instant [APIs](/docs/guides/api): APIs will be automatically generated when you create your database tables.+## Video demo-## Database set up+Coming soon.-### Create the scehma+Use the annotated timeline to step through this tutorial.++## Instant deploy++Want to deploy a completed version of this example without following the guide?++[](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2Fsupabase%2Fsupabase%2Ftree%2Fmaster%2Fexamples%2Freact-user-management&project-name=supabase-user-management&repository-name=supabase-user-management&demo-title=Supabase%20User%20Management&demo-description=An%20example%20web%20app%20using%20Supabase%20and%20Next.js&demo-url=https%3A%2F%2Fsupabase-react-user-management.vercel.app&demo-image=https%3A%2F%2Fi.imgur.com%2FZ3HkQqe.png&integration-ids=oac_jUduyjQgOyzev1fjrW83NYOv&external-id=nextjs-user-management)++Clicking this button the application will:++- Launch and prepare the Postgres database in Supabase.+- Launch the app in Vercel.+- Fork the example into your own GitHub account.+- Prepare the deployed application with all the necessary environment variables.++If you want to do it yourself, let's get started:++## Project set up++Before we start building we're going to set up our Database and API. This is as simple as starting a new Project in Supabase+and then creating a "schema" inside the database.++### Create a project++1. Go to [app.supabase.io](https://app.supabase.io).+1. Click on "New Project".+1. Enter your project details.+1. Wait for the new database to launch.+++### Set up the database schema++Now we are going to set up the database schema. We can use the "User Management Starter" quickstart in the SQL Editor,+or you can just copy/paste the SQL from below and run it yourself.<TabsdefaultValue="UI"@@ -95,43 +129,61 @@ create policy "Anyone can upload an avatar."### Get the API Keys-@todo - record video+Now that you've created some database tables, you are ready to insert data using the auto-generated API.+We just need to get the URL and `anon` key from the API settings.-## Basic App+<Tabs+defaultValue="UI"+values={[+ {label: 'UI', value: 'UI'}+]}>+<TabItem value="UI">++```sh+1. Go to the "Settings" section.+2. Click "API" in the sidebar.+3. Find your API URL in this page.+4. Find your "anon" and "service_role" keys on this page.+```-We're going to build XXX+<video width="99%" muted playsInline controls="true">+<source src="/videos/api/api-url-and-key.mp4" type="video/mp4" muted playsInline />+</video>+</TabItem>+</Tabs>-### Initialize a react app+## Basic App++Let's start building the React app from scratch.+### Initialize a react app-Create the react app:+We can use [Create React App](https://create-react-app.dev/docs/getting-started/) to initialize+an app called `supabase-react`:```bash-npx create-react-app supabase-react --use-npm+npx create-react-app supabase-react --use-npmcd supabase-react```-Install all the dependencies:+Then let's install the only additional dependency: [supabase-js](https://github.com/supabase/supabase-js)```bashnpm install @supabase/supabase-js```+And finally we want to save the environment variables in a `.env`.+All we need are the API URL and the `anon` key that you copied [earlier](#get-the-api-keys).-create a `.env` file--```bash-# .env-+```bash title=".env"REACT_APP_SUPABASE_URL=YOUR_SUPABASE_URLREACT_APP_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY```-set up the supabase library--Helper to initialize the Supabase client.+Now that we have the API credentials in place, let's create a helper file to initialize the Supabase client. These variables will be exposed+on the browser, and that's completely fine since we have [Row Level Security](/docs/guides/auth#row-level-security) enabled on our Database.```js title="src/supabaseClient.js"import { createClient } from '@supabase/supabase-js'@@ -142,13 +194,8 @@ const supabaseAnonKey = process.env.REACT_APP_SUPABASE_URLexport const supabase = createClient(supabaseUrl, supabaseAnonKey)```-Update index.css--```css-# Todo--```-+And one optional step is to update the CSS file to make the app look nice.+You can find the full contents of this file [here](https://github.com/supabase/supabase/blob/master/examples/react-user-management/src/index.js).### Set up a Login component@@ -328,20 +375,24 @@ export default function Account({ session }) {}```-### Run!+### Launch!+Run this in a terminal window:```bashnpm install start```+And then open the browser to [localhost:3000](http://localhost:3000) and you should see the completed app.-## Bonus: User avatar photos+## Bonus: Profile photos+Every Supabase project is configured with [Storage](/docs/guides/storage) for managing large files like photos and videos.-Add an uploader+### Create an upload widget+Let's create an avatar for the user so that they can upload a profile photo. We can start by creating a new component:```jsx title="src/Avatar.js"import { useEffect, useState } from 'react'@@ -432,18 +483,20 @@ export default function Avatar({ url, size, onUpload }) {```-Add the widget to the Account page+### Add the new widget+And then we can add the widget to the Account page:```jsx title="src/Account.js"+// Import the new componentimport Avatar from './Avatar'// ...return (<div className="form-widget">- {/* Add to the body */}+ {/* Add to the body */}<Avatarurl={avatar_url}size={150}@@ -452,8 +505,15 @@ return (updateProfile({ username, website, avatar_url: url })}}/>- {/* Add to the body */}+ {/* ... */}</div>)-```\ No newline at end of file+```++## Next steps++At this stage you have a fully functional application!++- Got a question? [Ask here](https://github.com/supabase/supabase/discussions).+- Sign in: app.supabase.io\ No newline at end of file