Skip to content

Commit

Permalink
Merge pull request #1170 from MoralisWeb3/readme-db-setup
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
ErnoW authored Nov 27, 2023
2 parents 4c9bd7f + 0898e2a commit 3fc8286
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
37 changes: 34 additions & 3 deletions demos/supabase-auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,40 @@
## 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 "Individuals can view their own user records."
on users for select
using ( (auth.jwt() ->> 'id')::bigint = id);
```

<img width="2294" alt="Screenshot 2023-11-26 at 12 23 04" src="https://github.com/MoralisWeb3/Moralis-JS-SDK/assets/11097108/994b0697-01cf-4e27-8f56-b9c50ea4b255">

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.

<img width="2276" alt="Screenshot 2023-11-26 at 12 23 48" src="https://github.com/MoralisWeb3/Moralis-JS-SDK/assets/11097108/cee7e888-4901-4ca0-ae61-dfd8418cb7f5">

You should see this if you click on that `1 active RLS policy`. This ensures that only authenticated users can view their data.

<img width="2560" alt="Screenshot 2023-11-26 at 12 24 57" src="https://github.com/MoralisWeb3/Moralis-JS-SDK/assets/11097108/f19956fc-54b0-493b-b7fb-79a0aa3f0b77">



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:

Expand Down
2 changes: 1 addition & 1 deletion demos/supabase-auth/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export default cleanEnv(process.env, {

SUPABASE_SERVICE_KEY: str(),

CLIENT_URL: str()
CLIENT_URL: str(),
});

1 comment on commit 3fc8286

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 20%
20.6% (61/296) 20.48% (17/83) 19.04% (12/63)
auth Coverage: 89%
92.45% (98/106) 83.33% (20/24) 86.66% (26/30)
evm-api Coverage: 91%
91.83% (90/98) 66.66% (6/9) 87.5% (56/64)
common-aptos-utils Coverage: 4%
4.56% (151/3306) 4.49% (25/556) 5.53% (45/813)
common-evm-utils Coverage: 64%
65.34% (1650/2525) 25% (186/744) 44.15% (419/949)
sol-api Coverage: 100%
100% (40/40) 66.66% (6/9) 100% (15/15)
common-sol-utils Coverage: 69%
69.04% (203/294) 51.42% (18/35) 55.67% (54/97)
common-streams-utils Coverage: 90%
90.73% (1204/1327) 73.63% (363/493) 82.07% (444/541)
streams Coverage: 91%
90.54% (603/666) 72.34% (68/94) 90.97% (131/144)

Please sign in to comment.