From cc1777cbac01f12572ff8c9548219b55c2e0b291 Mon Sep 17 00:00:00 2001 From: Ivan Liljeqvist Date: Sun, 26 Nov 2023 12:25:59 +0200 Subject: [PATCH 1/3] Update README.md --- demos/supabase-auth/README.md | 38 ++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/demos/supabase-auth/README.md b/demos/supabase-auth/README.md index 9bfb5cac69..e772195e56 100644 --- a/demos/supabase-auth/README.md +++ b/demos/supabase-auth/README.md @@ -3,9 +3,41 @@ ## Run locally 1. Create a supabase account here https://app.supabase.com/ -2. Copy `.env.example` to `.env` and fill in the values from your supabase dashboard and add the moralis api key -3. Open `public/script.js`, and fill in the values (located at the top of the file) from your supabase dashboard -4. Run `yarn dev` to run the server locally +2. You need to setup your Supabase Database so it can store your users. Go to `SQL Editor` in your Supabase account and run the following SQL query: + +``` +create table + public.users ( + id bigint generated by default as identity, + created_at timestamp with time zone not null default now(), + moralis_provider_id character varying null, + metadata json null, + constraint users_pkey primary key (id) + ) tablespace pg_default; + +alter table "public"."users" enable row level security; + +CREATE POLICY "Only authed users can SELECT their row" ON "public"."users" +AS PERMISSIVE FOR SELECT +TO authenticated +USING (true) +``` + +Screenshot 2023-11-26 at 12 23 04 + +If you view your database, you can double-check that the query was executed correctly. You should see a table called `users` with the following columns and `1 active RLS policy` at the top. + +Screenshot 2023-11-26 at 12 23 48 + +You should see this if you click on that `1 active RLS policy`. This ensures that only authenticated users can view their data. + +Screenshot 2023-11-26 at 12 24 57 + + + +4. Copy `.env.example` to `.env` and fill in the values from your supabase dashboard and add the moralis api key +5. Open `public/script.js`, and fill in the values (located at the top of the file) from your supabase dashboard +6. Run `yarn dev` to run the server locally Now your server is running locally with the following endpoints: From c2dcd77af9fe5bb278b9d7f1ad1f0d03721909c1 Mon Sep 17 00:00:00 2001 From: Ivan Liljeqvist Date: Sun, 26 Nov 2023 15:14:48 +0200 Subject: [PATCH 2/3] Update README.md --- demos/supabase-auth/README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/demos/supabase-auth/README.md b/demos/supabase-auth/README.md index e772195e56..1da193c84a 100644 --- a/demos/supabase-auth/README.md +++ b/demos/supabase-auth/README.md @@ -17,10 +17,9 @@ create table alter table "public"."users" enable row level security; -CREATE POLICY "Only authed users can SELECT their row" ON "public"."users" -AS PERMISSIVE FOR SELECT -TO authenticated -USING (true) +create policy "Individuals can view their own user records." +on users for select +using ( (auth.jwt() ->> 'id')::bigint = id); ``` Screenshot 2023-11-26 at 12 23 04 From 0898e2a11a4e500b3444e869fd6c7d9051b897e1 Mon Sep 17 00:00:00 2001 From: Erno Date: Mon, 27 Nov 2023 12:21:32 +0200 Subject: [PATCH 3/3] style: fix formatting --- demos/supabase-auth/src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/supabase-auth/src/config.ts b/demos/supabase-auth/src/config.ts index 1cd03d9514..4fa368ae07 100644 --- a/demos/supabase-auth/src/config.ts +++ b/demos/supabase-auth/src/config.ts @@ -18,5 +18,5 @@ export default cleanEnv(process.env, { SUPABASE_SERVICE_KEY: str(), - CLIENT_URL: str() + CLIENT_URL: str(), });