Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supabase SSR #135

Merged
merged 10 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ module.exports = {
},
},
},
{
// Apply to all test files. Proper type checking in tests with mocks can be tedious and counterproductive.
files: ["**/*.test.ts", "**/*.spec.ts"],
rules: {
"@typescript-eslint/no-explicit-any": "off",
},
},
],
env: {
browser: true,
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5

- name: NPM install
run: npm install

- name: Check Code Format
run: npm run format_check

- name: Download go misspell utility
run: go install github.com/client9/misspell/cmd/misspell@latest

- name: Run misspell to fine misspelled words
run: misspell -error ./src README.md
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
**/.svelte-kit/
**/node_modules/
**/package-lock.json

# Don't format plaintext email templates, the new lines are important
src/lib/emails/*_text.svelte
12 changes: 10 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "svelte.svelte-vscode",
"eslint.validate": ["javascript", "javascriptreact", "svelte"]
"[svelte]": {
"editor.defaultFormatter": "svelte.svelte-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"eslint.validate": ["javascript", "javascriptreact", "typescript", "svelte"]
}
148 changes: 107 additions & 41 deletions README.md

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

# error on first error
set -e
Copy link

Choose a reason for hiding this comment

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

Use /bin/bash in the shebang.

To ensure compatibility with the rest of the script, use /bin/bash instead of /bin/sh in the shebang.

-#!/bin/sh
+#!/bin/bash
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#!/bin/sh
# error on first error
set -e
#!/bin/bash
# error on first error
set -e


if ! command -v misspellx &> /dev/null
then
echo "=== Skipping Spell Check ==="
echo "Skip running spell check using 'misspell' as the tool is not installed."
echo "Install it using the instructions here: https://github.com/client9/misspell"
echo "Skipping this check now, but it may fail in CI.\n"
else
echo "=== Running Spell Check ==="
misspell -error ./src README.md
echo "no spelling mistakes found\n"
fi
Copy link

Choose a reason for hiding this comment

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

Use >/dev/null 2>&1 for redirection.

To ensure compatibility with POSIX sh, use >/dev/null 2>&1 for redirection.

-if ! command -v misspellx &> /dev/null
+if ! command -v misspellx >/dev/null 2>&1
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if ! command -v misspellx &> /dev/null
then
echo "=== Skipping Spell Check ==="
echo "Skip running spell check using 'misspell' as the tool is not installed."
echo "Install it using the instructions here: https://github.com/client9/misspell"
echo "Skipping this check now, but it may fail in CI.\n"
else
echo "=== Running Spell Check ==="
misspell -error ./src README.md
echo "no spelling mistakes found\n"
fi
if ! command -v misspellx >/dev/null 2>&1
then
echo "=== Skipping Spell Check ==="
echo "Skip running spell check using 'misspell' as the tool is not installed."
echo "Install it using the instructions here: https://github.com/client9/misspell"
echo "Skipping this check now, but it may fail in CI.\n"
else
echo "=== Running Spell Check ==="
misspell -error ./src README.md
echo "no spelling mistakes found\n"
fi
Tools
Shellcheck

[warning] 6-6: In POSIX sh, &> is undefined.

(SC3020)


echo "=== Running Format Check With Prettier ==="
npm run format_check

echo "=== Running Linter ==="
npm run lint

echo "=== Running Svelte Check ==="
npm run check

echo "=== Running Tests ==="
npm run test_run

echo "\n=== All Checks Pass ===\n"

5 changes: 3 additions & 2 deletions database_migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ create table profiles (
full_name text,
company_name text,
avatar_url text,
website text
website text,
unsubscribed boolean NOT NULL DEFAULT false
);
-- Set up Row Level Security (RLS)
-- See https://supabase.com/docs/guides/auth/row-level-security for more details.
Expand Down Expand Up @@ -69,4 +70,4 @@ create policy "Avatar images are publicly accessible." on storage.objects
for select using (bucket_id = 'avatars');

create policy "Anyone can upload an avatar." on storage.objects
for insert with check (bucket_id = 'avatars');
for insert with check (bucket_id = 'avatars');
45 changes: 45 additions & 0 deletions email_docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Email Setup

SaaS Starter includes email capabilities for sending emails to users, and admins.

There are three types of emails:

- Admin emails: sent to a static admin email address, useful for monitoring app activity like new signups and contact-us form submissions.
- User emails: sent to the user's email address. For example: a welcome email.
- Auth emails: verifing the user's email address and magic links. Auth emails are covered in the main README setup docs, and not covered here.

## Set Up Email

To enable email capabilities, set the following environment variables:

**Important**: The template includes a welcome email, which will be enabled once you set your Resend API key. You should customize the email to fit your brand and content or remove it **BEFORE** you enable the email with environment variables. See below.

- `PRIVATE_RESEND_API_KEY`: a https://resend.com API key. Note, you'll need to verify your 'from' domain with them before you can use their service.
- `PRIVATE_ADMIN_EMAIL`: the email address to which admin emails will be sent. If unset, admin emails will not be sent.
- `PRIVATE_FROM_ADMIN_EMAIL`: the email address to use as the from address for admin emails (defaults to `PRIVATE_ADMIN_EMAIL` if not set).
Copy link

Choose a reason for hiding this comment

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

Fix loose punctuation marks and bare URL.

The documentation has loose punctuation marks and a bare URL. Apply this diff to fix the issues:

- **Important**: The template includes a welcome email, which will be enabled once you set your Resend API key. You should customize the email to fit your brand and content or remove it **BEFORE** you enable the email with environment variables. See below.
- - `PRIVATE_RESEND_API_KEY`: a https://resend.com API key. Note, you'll need to verify your 'from' domain with them before you can use their service.
- - `PRIVATE_ADMIN_EMAIL`: the email address to which admin emails will be sent. If unset, admin emails will not be sent.
-   - `PRIVATE_FROM_ADMIN_EMAIL`: the email address to use as the from address for admin emails (defaults to `PRIVATE_ADMIN_EMAIL` if not set).
+ **Important**: The template includes a welcome email, which will be enabled once you set your Resend API key. You should customize the email to fit your brand and content or remove it **BEFORE** you enable the email with environment variables. See below.
+ - `PRIVATE_RESEND_API_KEY`: a [Resend API key](https://resend.com). Note, you'll need to verify your 'from' domain with them before you can use their service.
+ - `PRIVATE_ADMIN_EMAIL`: the email address to which admin emails will be sent. If unset, admin emails will not be sent.
+ - `PRIVATE_FROM_ADMIN_EMAIL`: the email address to use as the from address for admin emails (defaults to `PRIVATE_ADMIN_EMAIL` if not set).

Committable suggestion was skipped due to low confidence.

Tools
LanguageTool

[uncategorized] ~17-~17: Loose punctuation mark.
Context: .... See below. - PRIVATE_RESEND_API_KEY: a https://resend.com API key. Note, you...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~18-~18: Loose punctuation mark.
Context: ...e their service. - PRIVATE_ADMIN_EMAIL: the email address to which admin emails...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~19-~19: Loose punctuation mark.
Context: ... be sent. - PRIVATE_FROM_ADMIN_EMAIL: the email address to use as the from ad...

(UNLIKELY_OPENING_PUNCTUATION)

Markdownlint

17-17: null
Bare URL used

(MD034, no-bare-urls)


## Customize Welcome Email

SaaS Starter includes a welcome email template that you can customize to fit your brand and content. The email is sent to the user's email address when create their profile.

To customize the email:

- edit the properties like company name, from email, and subject in the call to sendTemplatedEmail in src/routes/(admin)/account/api/+page.server.ts
- edit the plaintext email content in src/lib/emails/welcome_email_text.svelte
- edit the html email content in src/lib/emails/welcome_email_html.svelte - don't forget address and preheader text which won't render in a preview, but will in the client's email client.

You can also delete the welcome email by removing the call to sendTemplatedEmail in src/routes/(admin)/account/api/+page.server.ts

## Adding Admin Emails

Anywhere you'd like to be notified of important events, you can sendan admin email.

Simply add a call to sendAdminEmail() in the appropriate place, passing a subject and body.

## Adding Additional User Emails

You can add more user emails. Create a template in src/lib/emails, using the welcome email as a guide. You should have both a plaintext and html version of the email (see welcome_email_text.svelte and welcome_email_html.svelte), although it will work with just one.

When you want to send the email, call sendUserEmail() with the appropriate parameters, including the name of the email template.

You can also use sendTemplatedEmail() to send emails to any email address.
8 changes: 8 additions & 0 deletions local_env_template
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Supabase settings
PUBLIC_SUPABASE_URL='https://REPLACE_ME.supabase.co'
PUBLIC_SUPABASE_ANON_KEY='REPLACE_ME'
PRIVATE_SUPABASE_SERVICE_ROLE='REPLACE_ME'

# Stripe settings
PRIVATE_STRIPE_API_KEY='REPLACE_ME'

# settings for email - optional
# PRIVATE_ADMIN_EMAIL='[email protected]'
# PRIVATE_FROM_ADMIN_EMAIL='REPLACE_ME'
# PRIVATE_RESEND_API_KEY='REPLACE_ME'
Loading
Loading