Skip to content

Commit 5f0a8ef

Browse files
authored
chore(docs): update nextjs slack clone (supabase#30894)
* chore(docs): wip update nextjs slack * chore: polish configtoml * chore: add next.config.js * chore: setup for valid nextjs deploy
1 parent 0531daa commit 5f0a8ef

File tree

6 files changed

+77
-136
lines changed

6 files changed

+77
-136
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Get these from your API settings: https://supabase.com/dashboard/project/_/settings/api
22

3-
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
4-
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
3+
NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321/
4+
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0
5+
NEXT_SITE_URL=http://localhost:3000
6+
NEXT_REDIRECT_URLS=http://localhost:3000/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Get these from your API settings: https://supabase.com/dashboard/project/_/settings/api
2+
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
3+
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
4+
# Get this from your Vercel project settings
5+
NEXT_SITE_URL=https://<your-vercel-project-name>.<your-vercel-org-name>.vercel.app/
6+
NEXT_REDIRECT_URLS=https://<your-vercel-project-name>.<your-vercel-org-name>.vercel.app/,https://<your-vercel-project-name>.<your-vercel-org-name>.vercel.app/**

examples/slack-clone/nextjs-slack-clone/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
# misc
1919
.DS_Store
2020
.env*
21-
!.env.local.example
21+
!.env.example
22+
!.env.production.example
2223

2324
# debug
2425
npm-debug.log*

examples/slack-clone/nextjs-slack-clone/README.md

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This is a full-stack Slack clone example using:
44

55
- Frontend:
6-
- Next.js.
6+
- [Next.js](https://github.com/vercel/next.js) - a React framework for production.
77
- [Supabase.js](https://supabase.com/docs/library/getting-started) for user management and realtime data syncing.
88
- Backend:
99
- [supabase.com/dashboard](https://supabase.com/dashboard/): hosted Postgres database with restful API for usage with Supabase.js.
@@ -14,7 +14,13 @@ This is a full-stack Slack clone example using:
1414

1515
![Demo animation gif](./public/slack-clone-demo.gif)
1616

17-
## Deploy your own
17+
## Deploy with Vercel
18+
19+
The Vercel deployment will guide you through creating a Supabase account and project. After installation of the Supabase integration, all relevant environment variables will be set up so that the project is usable immediately after deployment 🚀
20+
21+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fsupabase%2Fsupabase%2Ftree%2Fmaster%2Fexamples%2Fslack-clone%2Fnextjs-slack-clone&project-name=supabase-nextjs-slack-clone&repository-name=supabase-nextjs-slack-clone&integration-ids=oac_VqOgBHqhEoFTPzGkPd7L0iH6&external-id=https%3A%2F%2Fgithub.com%2Fsupabase%2Fsupabase%2Ftree%2Fmaster%2Fexamples%2Fslack-clone%2Fnextjs-slack-clone)
22+
23+
## Build from scratch
1824

1925
### 1. Create new project
2026

@@ -36,62 +42,49 @@ The `anon` key is your client-side API key. It allows "anonymous access" to your
3642

3743
**_NOTE_**: The `service_role` key has full access to your data, bypassing any security policies. These keys have to be kept secret and are meant to be used in server environments and never on a client or browser.
3844

39-
### 4. Deploy the Next.js client
40-
41-
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2Fsupabase%2Fsupabase%2Ftree%2Fmaster%2Fexamples%2Fslack-clone%2Fnextjs-slack-clone&env=NEXT_PUBLIC_SUPABASE_URL,NEXT_PUBLIC_SUPABASE_ANON_KEY&envDescription=Find%20the%20Supabase%20URL%20and%20key%20in%20the%20your%20auto-generated%20docs%20at%20supabase.com/dashboard&project-name=supabase-slack-clone&repo-name=supabase-slack-clone)
42-
43-
Here, we recommend forking this repo so you can deploy through Vercel by clicking the button above. When you click the button, replace the repo URL with your fork's URL.
44-
45-
You will be asked for a `NEXT_PUBLIC_SUPABASE_URL` and `NEXT_PUBLIC_SUPABASE_ANON_KEY`. Use the API URL and `anon` key from [step 3](#3-get-the-url-and-key).
46-
47-
### 5. Change authentication settings if necessary
48-
49-
![Change auth settings](https://user-images.githubusercontent.com/1811651/101840012-39be3800-3af8-11eb-8c32-73f2fae6299e.png)
50-
51-
On [supabase.com/dashboard](https://supabase.com/dashboard), you can go to Authentication -> Settings to change your auth settings for your project if necessary. Here, you can change the site URL, which is used for determining where to redirect users after they confirm their email addresses or attempt to use a magic link to log in.
52-
53-
Here, you can also enable external oauth providers, such as Google and GitHub.
54-
55-
## How to use
45+
## Supabase details
5646

57-
### Using this repo
47+
### Using a Remote Supabase Project
5848

59-
Simply clone this repo locally and proceed to the next section.
49+
1. Create or select a project on [Supabase Dashboard](https://supabase.com/dashboard).
50+
2. Copy and fill the dotenv template `cp .env.production.example .env.production`
51+
3. Link the local project and merge the local configuration with the remote one:
6052

61-
### Required configuration
53+
```bash
54+
SUPABASE_ENV=production npx supabase@latest link --project-ref <your-project-ref>
55+
```
6256

63-
Copy the `.env.example` file into a file named `.env.local` in the root directory of the example:
57+
3. Sync the configuration:
6458

6559
```bash
66-
cp .env.example .env.local
60+
SUPABASE_ENV=production npx supabase@latest config push
6761
```
6862

69-
Set your Supabase details from [step 3](#3-get-the-url-and-key) above:
63+
4. Sync the database schema:
7064

7165
```bash
72-
NEXT_PUBLIC_SUPABASE_URL=<replace-with-your-API-url>
73-
NEXT_PUBLIC_SUPABASE_ANON_KEY=<replace-with-your-anon-key>
66+
SUPABASE_ENV=production npx supabase@latest db push
7467
```
7568

76-
### Change authentication settings if necessary
69+
## Vercel Preview with Branching
7770

78-
Follow [Step #5](#5-change-authentication-settings-if-necessary) above if you want to change the auth settings.
71+
Supabase integrates seamlessly with Vercel's preview branches, giving each branch a dedicated Supabase project. This setup allows testing database migrations or service configurations safely before applying them to production.
7972

80-
### Run the development server
73+
### Steps
8174

82-
Now install the dependencies and start the development server.
75+
1. Ensure the Vercel project is linked to a Git repository.
76+
2. Configure the "Preview" environment variables in Vercel:
8377

84-
```bash
85-
npm install
86-
npm run dev
87-
# or
88-
yarn
89-
yarn dev
90-
```
78+
- `NEXT_PUBLIC_SUPABASE_URL`
79+
- `NEXT_PUBLIC_SUPABASE_ANON_KEY`
9180

92-
Visit http://localhost:3000 and start chatting! Open a channel across two browser tabs to see everything getting updated in realtime 🥳
81+
3. Create a new branch, make changes (e.g., update `max_frequency`), and push the branch to Git.
82+
- Open a pull request to trigger Vercel + Supabase integration.
83+
- Upon successful deployment, the preview environment reflects the changes.
9384

94-
## Supabase details
85+
![Preview Checks](https://github.com/user-attachments/assets/db688cc2-60fd-4463-bbed-e8ecc11b1a39)
86+
87+
---
9588

9689
### Role-based access control (RBAC)
9790

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
reactStrictMode: true,
4+
}
5+
6+
module.exports = nextConfig

examples/slack-clone/nextjs-slack-clone/supabase/config.toml

Lines changed: 26 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ enabled = true
88
port = 54321
99
# Schemas to expose in your API. Tables, views and stored procedures in this schema will get API
1010
# endpoints. public and storage are always included.
11-
schemas = ["public", "storage", "graphql_public"]
11+
schemas = ["public"]
1212
# Extra schemas to add to the search_path of every request. public is always included.
1313
extra_search_path = ["public", "extensions"]
1414
# The maximum number of rows returns from a view, table, or stored procedure. Limits payload size
@@ -24,52 +24,21 @@ shadow_port = 54320
2424
# server_version;` on the remote database to check.
2525
major_version = 15
2626

27-
[db.pooler]
28-
enabled = false
29-
# Port to use for the local connection pooler.
30-
port = 54329
31-
# Specifies when a server connection can be reused by other clients.
32-
# Configure one of the supported pooler modes: `transaction`, `session`.
33-
pool_mode = "transaction"
34-
# How many server connections to allow per user/database pair.
35-
default_pool_size = 20
36-
# Maximum number of client connections allowed.
37-
max_client_conn = 100
38-
3927
[realtime]
4028
enabled = true
4129
# Bind realtime via either IPv4 or IPv6. (default: IPv6)
4230
# ip_version = "IPv6"
4331

44-
[studio]
45-
enabled = true
46-
# Port to use for Supabase Studio.
47-
port = 54323
48-
# External URL of the API server that frontend connects to.
49-
api_url = "http://127.0.0.1"
50-
51-
# Email testing server. Emails sent with the local dev setup are not actually sent - rather, they
52-
# are monitored, and you can view the emails that would have been sent from the web interface.
53-
[inbucket]
54-
enabled = true
55-
# Port to use for the email testing server web interface.
56-
port = 54324
57-
# Uncomment to expose additional ports for testing user applications that send emails.
58-
# smtp_port = 54325
59-
# pop3_port = 54326
60-
61-
[storage]
62-
enabled = true
63-
# The maximum file size allowed (e.g. "5MB", "500KB").
64-
file_size_limit = "50MiB"
65-
6632
[auth]
6733
enabled = true
6834
# The base URL of your website. Used as an allow-list for redirects and for constructing URLs used
6935
# in emails.
70-
site_url = "http://127.0.0.1:3000"
36+
site_url = "env(NEXT_SITE_URL)"
7137
# A list of *exact* URLs that auth providers are permitted to redirect to post authentication.
72-
additional_redirect_urls = ["https://127.0.0.1:3000"]
38+
additional_redirect_urls = [
39+
# Will be localhost:3000 in development or the URL of your deployed app in production.
40+
"env(NEXT_REDIRECT_URLS)",
41+
]
7342
# How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 (1 week).
7443
jwt_expiry = 3600
7544
# If disabled, the refresh token will never expire.
@@ -87,46 +56,27 @@ enable_signup = true
8756
# addresses. If disabled, only the new email is required to confirm.
8857
double_confirm_changes = true
8958
# If enabled, users need to confirm their email address before signing in.
90-
enable_confirmations = false
91-
92-
# Uncomment to customize email template
93-
# [auth.email.template.invite]
94-
# subject = "You have been invited"
95-
# content_path = "./supabase/templates/invite.html"
59+
enable_confirmations = true
60+
# If enabled, users will need to reauthenticate or have logged in recently to change their password.
61+
secure_password_change = false
62+
# Controls the minimum amount of time that must pass before sending another signup confirmation or password reset email.
63+
max_frequency = "1m0s"
64+
# Number of characters used in the email OTP.
65+
otp_length = 6
66+
# Number of seconds before the email OTP expires (defaults to 1 hour).
67+
otp_expiry = 3600
9668

97-
[auth.sms]
98-
# Allow/disallow new user signups via SMS to your project.
99-
enable_signup = true
100-
# If enabled, users need to confirm their phone number before signing in.
101-
enable_confirmations = false
102-
# Template for sending OTP to users
103-
template = "Your code is {{ .Code }} ."
104-
105-
# Use pre-defined map of phone number to OTP for testing.
106-
[auth.sms.test_otp]
107-
# 4152127777 = "123456"
108-
109-
# Configure one of the supported SMS providers: `twilio`, `twilio_verify`, `messagebird`, `textlocal`, `vonage`.
110-
[auth.sms.twilio]
111-
enabled = false
112-
account_sid = ""
113-
message_service_sid = ""
114-
# DO NOT commit your Twilio auth token to git. Use environment variable substitution instead:
115-
auth_token = "env(SUPABASE_AUTH_SMS_TWILIO_AUTH_TOKEN)"
116-
117-
# Use an external OAuth provider. The full list of providers are: `apple`, `azure`, `bitbucket`,
118-
# `discord`, `facebook`, `github`, `gitlab`, `google`, `keycloak`, `linkedin`, `notion`, `twitch`,
119-
# `twitter`, `slack`, `spotify`, `workos`, `zoom`.
120-
[auth.external.apple]
121-
enabled = false
122-
client_id = ""
123-
# DO NOT commit your OAuth provider secret to git. Use environment variable substitution instead:
124-
secret = "env(SUPABASE_AUTH_EXTERNAL_APPLE_SECRET)"
125-
# Overrides the default auth redirectUrl.
126-
redirect_uri = ""
127-
# Overrides the default auth provider URL. Used to support self-hosted gitlab, single-tenant Azure,
128-
# or any other third-party OIDC providers.
129-
url = ""
69+
# Email testing server. Emails sent with the local dev setup are not actually sent - rather, they
70+
# are monitored, and you can view the emails that would have been sent from the web interface.
71+
[inbucket]
72+
enabled = true
73+
# Port to use for the email testing server web interface.
74+
port = 54324
75+
# Uncomment to expose additional ports for testing user applications that send emails.
76+
# smtp_port = 54325
77+
# pop3_port = 54326
78+
# admin_email = "[email protected]"
79+
# sender_name = "Admin"
13080

13181
# Enable auth hooks
13282
# https://supabase.com/docs/guides/auth/auth-hooks#local-development
@@ -136,20 +86,3 @@ uri = "pg-functions://postgres/public/custom_access_token_hook"
13686

13787
[analytics]
13888
enabled = false
139-
port = 54327
140-
vector_port = 54328
141-
# Configure one of the supported backends: `postgres`, `bigquery`.
142-
backend = "postgres"
143-
144-
# Experimental features may be deprecated any time
145-
[experimental]
146-
# Configures Postgres storage engine to use OrioleDB (S3)
147-
orioledb_version = ""
148-
# Configures S3 bucket URL, eg. <bucket_name>.s3-<region>.amazonaws.com
149-
s3_host = "env(S3_HOST)"
150-
# Configures S3 bucket region, eg. us-east-1
151-
s3_region = "env(S3_REGION)"
152-
# Configures AWS_ACCESS_KEY_ID for S3 bucket
153-
s3_access_key = "env(S3_ACCESS_KEY)"
154-
# Configures AWS_SECRET_ACCESS_KEY for S3 bucket
155-
s3_secret_key = "env(S3_SECRET_KEY)"

0 commit comments

Comments
 (0)