Skip to content

Commit 6502e6d

Browse files
authored
V2 (#52)
Major changes : * Supabase JS SDK V2 😇 * Folder structure * Previous module's mutations/queries are now in a `service.server` (collocate all the module's service in one place) * Auth session is reworked to align with folder structure changes * `requireAuthSession` no longer call Supabase Auth API by default to verify user access token (it's still safe, we signed our cookie) * `requireAuthSession` takes a new optional param called `verify` (boolean) to work as before 😉 * No more needing to start a shadow database to create a Prisma migration (I don't know why maybe it's thanks to Supabase). It results in a huge time saving!
1 parent 032a98e commit 6502e6d

File tree

91 files changed

+937
-1963
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+937
-1963
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/build
2+
/public/build
3+
*.config*
4+
/test/

.eslintrc

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"plugins": ["tailwindcss"],
3+
"extends": [
4+
"@remix-run/eslint-config",
5+
"@remix-run/eslint-config/node",
6+
"plugin:tailwindcss/recommended",
7+
"prettier"
8+
],
9+
"parserOptions": {
10+
"project": ["./tsconfig.json"]
11+
},
12+
"settings": {
13+
// Help eslint-plugin-tailwindcss to parse Tailwind classes outside of className
14+
"tailwindcss": {
15+
"callees": ["tw"]
16+
},
17+
"jest": {
18+
"version": 27
19+
}
20+
},
21+
"rules": {
22+
"no-console": "warn",
23+
"arrow-body-style": ["warn", "as-needed"],
24+
// @typescript-eslint
25+
"@typescript-eslint/no-duplicate-imports": "error",
26+
"@typescript-eslint/consistent-type-imports": "error",
27+
"@typescript-eslint/no-unused-vars": [
28+
"warn",
29+
{
30+
"vars": "all",
31+
"args": "all",
32+
"argsIgnorePattern": "^_",
33+
"destructuredArrayIgnorePattern": "^_",
34+
"ignoreRestSiblings": false
35+
}
36+
],
37+
//import
38+
"import/no-cycle": "error",
39+
"import/no-unresolved": "error",
40+
"import/no-default-export": "warn",
41+
"import/order": [
42+
"error",
43+
{
44+
"groups": ["builtin", "external", "internal"],
45+
"pathGroups": [
46+
{
47+
"pattern": "react",
48+
"group": "external",
49+
"position": "before"
50+
}
51+
],
52+
"pathGroupsExcludedImportTypes": ["react"],
53+
"newlines-between": "always",
54+
"alphabetize": {
55+
"order": "asc",
56+
"caseInsensitive": true
57+
}
58+
}
59+
]
60+
},
61+
"overrides": [
62+
{
63+
"files": [
64+
"./app/root.tsx",
65+
"./app/entry.client.tsx",
66+
"./app/entry.server.tsx",
67+
"./app/routes/**/*.tsx"
68+
],
69+
"rules": {
70+
"import/no-default-export": "off"
71+
}
72+
}
73+
]
74+
}

.eslintrc.js

Lines changed: 0 additions & 110 deletions
This file was deleted.

.github/workflows/deploy.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: 🛑 Cancel Previous Runs
18-
uses: styfle/cancel-workflow-action@0.9.1
18+
uses: styfle/cancel-workflow-action@0.11.0
1919

2020
- name: ⬇️ Checkout repo
2121
uses: actions/checkout@v3
@@ -41,7 +41,7 @@ jobs:
4141
runs-on: ubuntu-latest
4242
steps:
4343
- name: 🛑 Cancel Previous Runs
44-
uses: styfle/cancel-workflow-action@0.9.1
44+
uses: styfle/cancel-workflow-action@0.11.0
4545

4646
- name: ⬇️ Checkout repo
4747
uses: actions/checkout@v3
@@ -64,7 +64,7 @@ jobs:
6464
runs-on: ubuntu-latest
6565
steps:
6666
- name: 🛑 Cancel Previous Runs
67-
uses: styfle/cancel-workflow-action@0.9.1
67+
uses: styfle/cancel-workflow-action@0.11.0
6868

6969
- name: ⬇️ Checkout repo
7070
uses: actions/checkout@v3
@@ -87,7 +87,7 @@ jobs:
8787
runs-on: ubuntu-latest
8888
steps:
8989
- name: 🛑 Cancel Previous Runs
90-
uses: styfle/cancel-workflow-action@0.9.1
90+
uses: styfle/cancel-workflow-action@0.11.0
9191

9292
- name: ⬇️ Checkout repo
9393
uses: actions/checkout@v3
@@ -137,7 +137,7 @@ jobs:
137137
runs-on: ubuntu-latest
138138
steps:
139139
- name: 🛑 Cancel Previous Runs
140-
uses: styfle/cancel-workflow-action@0.9.1
140+
uses: styfle/cancel-workflow-action@0.11.0
141141

142142
- name: ⬇️ Checkout repo
143143
uses: actions/checkout@v3
@@ -198,7 +198,7 @@ jobs:
198198

199199
steps:
200200
- name: 🛑 Cancel Previous Runs
201-
uses: styfle/cancel-workflow-action@0.9.1
201+
uses: styfle/cancel-workflow-action@0.11.0
202202

203203
- name: ⬇️ Checkout repo
204204
uses: actions/checkout@v3

.github/workflows/for-this-stack-repo-only.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: 🛑 Cancel Previous Runs
18-
uses: styfle/cancel-workflow-action@0.9.1
18+
uses: styfle/cancel-workflow-action@0.11.0
1919

2020
- name: ⬇️ Checkout repo
2121
uses: actions/checkout@v3
@@ -41,7 +41,7 @@ jobs:
4141
runs-on: ubuntu-latest
4242
steps:
4343
- name: 🛑 Cancel Previous Runs
44-
uses: styfle/cancel-workflow-action@0.9.1
44+
uses: styfle/cancel-workflow-action@0.11.0
4545

4646
- name: ⬇️ Checkout repo
4747
uses: actions/checkout@v3
@@ -64,7 +64,7 @@ jobs:
6464
runs-on: ubuntu-latest
6565
steps:
6666
- name: 🛑 Cancel Previous Runs
67-
uses: styfle/cancel-workflow-action@0.9.1
67+
uses: styfle/cancel-workflow-action@0.11.0
6868

6969
- name: ⬇️ Checkout repo
7070
uses: actions/checkout@v3
@@ -88,7 +88,7 @@ jobs:
8888
needs: [lint, typecheck, vitest]
8989
steps:
9090
- name: 🛑 Cancel Previous Runs
91-
uses: styfle/cancel-workflow-action@0.9.1
91+
uses: styfle/cancel-workflow-action@0.11.0
9292

9393
- name: ⬇️ Checkout repo
9494
uses: actions/checkout@v3

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pnpm-lock.yml
77

88
node_modules
99

10+
/.cache
1011
/build
1112
/public/build
1213
.env

README.md

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ npx create-remix --template rphlmr/supa-fly-stack
1515
- [Fly app deployment](https://fly.io) with [Docker](https://www.docker.com/products/docker-desktop/)
1616
- Production-ready [Supabase Database](https://supabase.com/)
1717
- Healthcheck endpoint for [Fly backups region fallbacks](https://fly.io/docs/reference/configuration/#services-http_checks)
18-
- [GitHub Actions](https://github.com/features/actions) for deploy on merge to production and staging environments
19-
- Email/Password Authentication with [cookie-based sessions](https://remix.run/docs/en/v1/api/remix#createcookiesessionstorage)
20-
- **NEW** : Magic Link login 🥳
18+
- [GitHub Actions](https://github.com/features/actions) to deploy on merge to production and staging environments
19+
- Email/Password Authentication / Magic Link, with [cookie-based sessions](https://remix.run/docs/en/v1/api/remix#createcookiesessionstorage)
2120
- Database ORM with [Prisma](https://prisma.io)
2221
- Forms Schema (client and server sides !) validation with [Remix Params Helper](https://github.com/kiliman/remix-params-helper)
2322
- Styling with [Tailwind](https://tailwindcss.com/)
@@ -32,7 +31,7 @@ Not a fan of bits of the stack? Fork it, change it, and use `npx create-remix --
3231

3332
## Development
3433

35-
- Create a [Supabase Database](https://supabase.com/) (Free tiers gives you 2 databases)
34+
- Create a [Supabase Database](https://supabase.com/) (free tier gives you 2 databases)
3635

3736
> **Note:** Only one for playing around with Supabase or 2 for `staging` and `production`
3837
@@ -84,7 +83,7 @@ The database seed script creates a new user with some data you can use to get st
8483

8584
### Relevant code:
8685

87-
This is a pretty simple note-taking app, but it's a good example of how you can build a full stack app with Prisma, Supabase and Remix. The main functionality is creating users, logging in and out (handling access and refresh tokens + refresh on expire), and creating and deleting notes.
86+
This is a pretty simple note-taking app, but it's a good example of how you can build a full-stack app with Prisma, Supabase, and Remix. The main functionality is creating users, logging in and out (handling access and refresh tokens + refresh on expiration), and creating and deleting notes.
8887

8988
- auth / session [./app/modules/auth](./app/modules/auth)
9089
- creating, and deleting notes [./app/modules/note](./app/modules/note)
@@ -197,7 +196,7 @@ For lower level tests of utilities and individual components, we use `vitest`. W
197196

198197
### Type Checking
199198

200-
This project uses TypeScript. It's recommended to get TypeScript set up for your editor to get a really great in-editor experience with type checking and auto-complete. To run type checking across the whole project, run `npm run typecheck`.
199+
This project uses TypeScript. It's recommended to get TypeScript set up for your editor to get a great in-editor experience with type checking and auto-complete. To run type checking across the whole project, run `npm run typecheck`.
201200

202201
### Linting
203202

@@ -209,48 +208,30 @@ We use [Prettier](https://prettier.io/) for auto-formatting in this project. It'
209208

210209
## Start working with Supabase
211210

212-
Your are now ready to go further, congrats !
213-
214-
To extend your prisma schema and apply changes on your supabase database :
215-
216-
- Download and run [Docker Desktop](https://www.docker.com/products/docker-desktop/)
217-
218-
> **Note:** Needed to create a [shadow database for prisma](https://www.prisma.io/docs/concepts/components/prisma-migrate/shadow-database)
219-
220-
> **Note:** Shadow database is local and run by `docker-compose.yml`
211+
You are now ready to go further, congrats!
221212

213+
To extend your Prisma schema and apply changes on your supabase database :
222214
- Make your changes in [./app/database/schema.prisma](./app/database/schema.prisma)
223215
- Prepare your schema migration
224-
225-
> **Note:** First time take a long moment 😅
226-
227216
```sh
228217
npm run db:prepare-migration
229218
```
230-
231-
- Check your migration in [./app/database/migrations](./app/database/migrations)
232-
- Apply this migration in production
219+
- Check your migration in [./app/database/migrations](./app/database)
220+
- Apply this migration to production
233221

234222
```sh
235223
npm run db:deploy-migration
236224
```
237225

238-
## Use with Supabase RLS
239-
240-
> To test this stack with RLS, you can find a demo in [./app/routes/rls](./app/routes/rls)
241-
242-
> **Before playing, add some RLS rules for "Note" table**
243-
244-
| Policy name | Target roles | WITH CHECK expression |
245-
| ---------------------------------- | :-----------: | -------------------------: |
246-
| Creator can see their own notes | authenticated | ((uid())::text = "userId") |
247-
| Authenticated user can add notes | authenticated | true |
248-
| Creator can delete their own posts | authenticated | ((uid())::text = "userId") |
226+
## If your token expires in less than 1 hour (3600 seconds in Supabase Dashboard)
249227

250-
> Then, go to [http://localhost:3000/rls/notes](http://localhost:3000/rls/notes)
228+
If you have a lower token lifetime than me (1 hour), you should take a look at `REFRESH_ACCESS_TOKEN_THRESHOLD` in [./app/modules/auth/session.server.ts](./app/modules/auth/session.server.ts) and set what you think is the best value for your use case.
251229

252-
## Your token expires in less than 1 hour (3600 seconds in Supabase Dashboard)
230+
## Supabase RLS
231+
You may ask "can I use RLS with Remix".
253232

254-
If you have a lower token lifetime than me (1 hour), you should take a look at `REFRESH_THRESHOLD` in [./app/modules/auth/const.ts](./app/modules/auth/const.ts) and set what you think is the best value for your use case.
233+
The answer is "Yes" but It has a cost.
255234

235+
Using Supabase SDK server side to query your database (for those using RLS features) adds an extra delay due to calling a Gotrue rest API instead of directly calling the Postgres database (and this is fine because at first Supabase SDK is for those who don't have/want backend).
256236

237+
In my benchmark, it makes my pages twice slower. (~+200ms compared to a direct query with Prisma)

0 commit comments

Comments
 (0)