Refactor getServiceRoleKey function and update README.md

Temporarily reverted tainting. It doesn't work sometimes.
This commit is contained in:
giancarlo
2024-04-18 14:55:23 +08:00
parent 0fc2581b11
commit 0dfd5d8ec1
2 changed files with 31 additions and 13 deletions

View File

@@ -304,7 +304,8 @@ While you can create a migration to add the database webhooks, you can also add
3. Click on "Enable Webhooks" 3. Click on "Enable Webhooks"
4. Click on "Create a new hook" 4. Click on "Create a new hook"
Now, replicate thr webhooks at `apps/web/supabase/seed.sql` using the UI: Now, replicate the webhooks at `apps/web/supabase/seed.sql` using the UI:
1. Please remember to set the `X-Supabase-Event-Signature` header with the value of the `SUPABASE_DB_WEBHOOK_SECRET` to the request. 1. Please remember to set the `X-Supabase-Event-Signature` header with the value of the `SUPABASE_DB_WEBHOOK_SECRET` to the request.
2. Please remember to set the endpoint to `/api/db/webhook` using your real APP URL. If your APP URL is `https://myapp.vercel.app`, the endpoint will be `https://myapp.vercel.app/api/db/webhook`. 2. Please remember to set the endpoint to `/api/db/webhook` using your real APP URL. If your APP URL is `https://myapp.vercel.app`, the endpoint will be `https://myapp.vercel.app/api/db/webhook`.
3. Use 5000 as the timeout. 3. Use 5000 as the timeout.
@@ -320,6 +321,33 @@ Remember to update the mailing sender in Supabase too, as the default sender is
You can do so from Settings->Authentication->SMTP Settings. You can do so from Settings->Authentication->SMTP Settings.
## Development Gotchas
When you update the repository - I found it best to clear the workspaces and reinstall the dependencies.
```bash
pnpm run clear:workspaces
pnpm run clear
```
Then, reinstall the dependencies:
```bash
pnpm i
```
PNPM is so fast this won't take long.
Sometimes - you will see errors when running the Dev Server (sometimes it's Turbopack, and sometimes pnpm uses a different version of React).
While I figure this stuff out, in these cases, please re-run the Dev Server:
```bash
pnpm dev
```
If necessary, repeat the process above.
## Deploying to Vercel ## Deploying to Vercel
Deploying to Vercel is straightforward. You can deploy the application using the Vercel CLI or the Vercel dashboard. Deploying to Vercel is straightforward. You can deploy the application using the Vercel CLI or the Vercel dashboard.

View File

@@ -1,11 +1,9 @@
import 'server-only'; import 'server-only';
import { experimental_taintUniqueValue as taintUniqueValue } from 'react';
import { z } from 'zod'; import { z } from 'zod';
const message = const message =
'Invalid Supabase Service Role Key. Please check the environment variable SUPABASE_SERVICE_ROLE_KEY.'; 'Invalid Supabase Service Role Key. Please add the environment variable SUPABASE_SERVICE_ROLE_KEY.';
/** /**
* @name getServiceRoleKey * @name getServiceRoleKey
@@ -13,7 +11,7 @@ const message =
* ONLY USE IN SERVER-SIDE CODE. DO NOT EXPOSE THIS TO CLIENT-SIDE CODE. * ONLY USE IN SERVER-SIDE CODE. DO NOT EXPOSE THIS TO CLIENT-SIDE CODE.
*/ */
export function getServiceRoleKey() { export function getServiceRoleKey() {
const serviceRoleKey = z return z
.string({ .string({
required_error: message, required_error: message,
}) })
@@ -21,14 +19,6 @@ export function getServiceRoleKey() {
message: message, message: message,
}) })
.parse(process.env.SUPABASE_SERVICE_ROLE_KEY); .parse(process.env.SUPABASE_SERVICE_ROLE_KEY);
taintUniqueValue(
'Do not pass the service role key to the client',
process,
serviceRoleKey,
);
return serviceRoleKey;
} }
/** /**