feat:authentication

This commit is contained in:
Damien Ostler 2024-05-24 17:57:03 -04:00
parent fac7ebd382
commit cc194b239b
39 changed files with 3616 additions and 21 deletions

5
.env
View File

@ -1,3 +1,2 @@
NEXT_APPWRITE_KEY=2373e8ebda066d8cf7051189bda95eada44fccfc45df9cafff35a118b789d6ea86a49ca5fad47f417f8e24f4a686e97b1299d919bd1f003a0dd04492663ac0853f270e0e225c0c4bd12bebd4c7de68d3fbd2e4fa758b0d4c4abd568324a7b072b77e671460caea1cd4811e4c00f1cdc8a2c5b755e3e578b35d8ec3ddf7004173
NEXT_PUBLIC_APPWRITE_ENDPOINT=http://localhost/v1
NEXT_PUBLIC_APPWRITE_PROJECT=664fdcac0006a5bbd335
NEXT_PUBLIC_SUPABASE_URL=http://localhost:8000
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJhbm9uIiwKICAgICJpc3MiOiAic3VwYWJhc2UtZGVtbyIsCiAgICAiaWF0IjogMTY0MTc2OTIwMCwKICAgICJleHAiOiAxNzk5NTM1NjAwCn0.dc_X5iR_VP_qT0zsiyj_I_OZ2T9FtRU2BBNWN8Bu4GE

4
.env.example Normal file
View File

@ -0,0 +1,4 @@
# Update these with your Supabase details from your project settings > API
# https://app.supabase.com/project/_/settings/api
NEXT_PUBLIC_SUPABASE_URL=your-project-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key

357
.gitignore vendored
View File

@ -17,7 +17,8 @@ yarn-error.log*
#local env files
.env*.local
/maildev
/owncast
/coverage
supabase/volumes/db/data/postmaster.pid
supabase/volumes/db/data/pg_xact/0000
@ -369,3 +370,357 @@ supabase/volumes/db/data/base/1/2619_vm
supabase/volumes/db/data/base/1/2619_fsm
supabase/volumes/db/data/base/1/2619
supabase/volumes/db/data/base/1/1259
supabase/volumes/db/data/postmaster.pid
supabase/volumes/db/data/pg_xact/0000
supabase/volumes/db/data/pg_wal/000000010000000000000003
supabase/volumes/db/data/pg_wal/000000010000000000000001
supabase/volumes/db/data/pg_subtrans/0000
supabase/volumes/db/data/pg_stat_tmp/pgss_query_texts.stat
supabase/volumes/db/data/pg_replslot/cainophile_s38zcwp1/state
supabase/volumes/db/data/pg_replslot/cainophile_geatpn94/state
supabase/volumes/db/data/pg_logical/snapshots/0-219E100.snap
supabase/volumes/db/data/pg_logical/snapshots/0-219E030.snap
supabase/volumes/db/data/pg_logical/snapshots/0-219DF68.snap
supabase/volumes/db/data/pg_logical/snapshots/0-219DF30.snap
supabase/volumes/db/data/pg_logical/snapshots/0-219C118.snap
supabase/volumes/db/data/pg_logical/snapshots/0-219B090.snap
supabase/volumes/db/data/pg_logical/snapshots/0-218F998.snap
supabase/volumes/db/data/pg_logical/snapshots/0-218E538.snap
supabase/volumes/db/data/pg_logical/snapshots/0-2188658.snap
supabase/volumes/db/data/pg_logical/snapshots/0-2181458.snap
supabase/volumes/db/data/pg_logical/snapshots/0-2180B58.snap
supabase/volumes/db/data/pg_logical/snapshots/0-2177990.snap
supabase/volumes/db/data/pg_logical/snapshots/0-1CC28B0.snap
supabase/volumes/db/data/pg_logical/snapshots/0-1CBC9C0.snap
supabase/volumes/db/data/pg_logical/snapshots/0-1CB8D18.snap
supabase/volumes/db/data/pg_logical/snapshots/0-1CA97A8.snap
supabase/volumes/db/data/pg_logical/snapshots/0-1C9FDD8.snap
supabase/volumes/db/data/pg_logical/snapshots/0-1C44448.snap
supabase/volumes/db/data/pg_logical/snapshots/0-1C247B0.snap
supabase/volumes/db/data/pg_logical/snapshots/0-1BB38E0.snap
supabase/volumes/db/data/global/pg_control
supabase/volumes/db/data/global/2964
supabase/volumes/db/data/global/2695
supabase/volumes/db/data/global/2694
supabase/volumes/db/data/global/2677
supabase/volumes/db/data/global/2676
supabase/volumes/db/data/global/1261
supabase/volumes/db/data/global/1260
supabase/volumes/db/data/global/1233
supabase/volumes/db/data/global/1232
supabase/volumes/db/data/global/1214_vm
supabase/volumes/db/data/global/1214_fsm
supabase/volumes/db/data/global/1214
supabase/volumes/db/data/base/5/6116
supabase/volumes/db/data/base/5/6113
supabase/volumes/db/data/base/5/6112
supabase/volumes/db/data/base/5/6111
supabase/volumes/db/data/base/5/6110
supabase/volumes/db/data/base/5/6106
supabase/volumes/db/data/base/5/6104
supabase/volumes/db/data/base/5/5002
supabase/volumes/db/data/base/5/3534
supabase/volumes/db/data/base/5/3503
supabase/volumes/db/data/base/5/3502
supabase/volumes/db/data/base/5/3501
supabase/volumes/db/data/base/5/3455
supabase/volumes/db/data/base/5/2841
supabase/volumes/db/data/base/5/2840_vm
supabase/volumes/db/data/base/5/2840_fsm
supabase/volumes/db/data/base/5/2840
supabase/volumes/db/data/base/5/2838_fsm
supabase/volumes/db/data/base/5/2838
supabase/volumes/db/data/base/5/2837
supabase/volumes/db/data/base/5/2836_vm
supabase/volumes/db/data/base/5/2836_fsm
supabase/volumes/db/data/base/5/2836
supabase/volumes/db/data/base/5/2704
supabase/volumes/db/data/base/5/2703
supabase/volumes/db/data/base/5/2702
supabase/volumes/db/data/base/5/2701
supabase/volumes/db/data/base/5/2699
supabase/volumes/db/data/base/5/2696
supabase/volumes/db/data/base/5/2693
supabase/volumes/db/data/base/5/2691
supabase/volumes/db/data/base/5/2690
supabase/volumes/db/data/base/5/2685
supabase/volumes/db/data/base/5/2684
supabase/volumes/db/data/base/5/2679
supabase/volumes/db/data/base/5/2678
supabase/volumes/db/data/base/5/2675
supabase/volumes/db/data/base/5/2674
supabase/volumes/db/data/base/5/2673
supabase/volumes/db/data/base/5/2667
supabase/volumes/db/data/base/5/2666
supabase/volumes/db/data/base/5/2665
supabase/volumes/db/data/base/5/2664
supabase/volumes/db/data/base/5/2663
supabase/volumes/db/data/base/5/2662
supabase/volumes/db/data/base/5/2659
supabase/volumes/db/data/base/5/2658
supabase/volumes/db/data/base/5/2657
supabase/volumes/db/data/base/5/2656
supabase/volumes/db/data/base/5/2620_vm
supabase/volumes/db/data/base/5/2620_fsm
supabase/volumes/db/data/base/5/2620
supabase/volumes/db/data/base/5/2619_vm
supabase/volumes/db/data/base/5/2619_fsm
supabase/volumes/db/data/base/5/2619
supabase/volumes/db/data/base/5/2618_fsm
supabase/volumes/db/data/base/5/2618
supabase/volumes/db/data/base/5/2615
supabase/volumes/db/data/base/5/2610_fsm
supabase/volumes/db/data/base/5/2610
supabase/volumes/db/data/base/5/2609_fsm
supabase/volumes/db/data/base/5/2609
supabase/volumes/db/data/base/5/2608_vm
supabase/volumes/db/data/base/5/2608_fsm
supabase/volumes/db/data/base/5/2608
supabase/volumes/db/data/base/5/2606_fsm
supabase/volumes/db/data/base/5/2606
supabase/volumes/db/data/base/5/2604_fsm
supabase/volumes/db/data/base/5/2604
supabase/volumes/db/data/base/5/2600_fsm
supabase/volumes/db/data/base/5/2600
supabase/volumes/db/data/base/5/2579
supabase/volumes/db/data/base/5/2224
supabase/volumes/db/data/base/5/18190
supabase/volumes/db/data/base/5/18176
supabase/volumes/db/data/base/5/18165
supabase/volumes/db/data/base/5/18143
supabase/volumes/db/data/base/5/18133
supabase/volumes/db/data/base/5/18132
supabase/volumes/db/data/base/5/18131
supabase/volumes/db/data/base/5/18130
supabase/volumes/db/data/base/5/18129
supabase/volumes/db/data/base/5/18128
supabase/volumes/db/data/base/5/18127
supabase/volumes/db/data/base/5/18098
supabase/volumes/db/data/base/5/18096
supabase/volumes/db/data/base/5/18094
supabase/volumes/db/data/base/5/18093
supabase/volumes/db/data/base/5/18092
supabase/volumes/db/data/base/5/18087
supabase/volumes/db/data/base/5/18086
supabase/volumes/db/data/base/5/18067
supabase/volumes/db/data/base/5/18064
supabase/volumes/db/data/base/5/18047
supabase/volumes/db/data/base/5/18035
supabase/volumes/db/data/base/5/18034
supabase/volumes/db/data/base/5/18033
supabase/volumes/db/data/base/5/18027
supabase/volumes/db/data/base/5/18020
supabase/volumes/db/data/base/5/18019
supabase/volumes/db/data/base/5/18018
supabase/volumes/db/data/base/5/18013
supabase/volumes/db/data/base/5/17953
supabase/volumes/db/data/base/5/17951
supabase/volumes/db/data/base/5/17944
supabase/volumes/db/data/base/5/17939
supabase/volumes/db/data/base/5/17938
supabase/volumes/db/data/base/5/17936
supabase/volumes/db/data/base/5/17930
supabase/volumes/db/data/base/5/17928
supabase/volumes/db/data/base/5/17925
supabase/volumes/db/data/base/5/17924
supabase/volumes/db/data/base/5/17923
supabase/volumes/db/data/base/5/17922
supabase/volumes/db/data/base/5/17915
supabase/volumes/db/data/base/5/17907
supabase/volumes/db/data/base/5/17893
supabase/volumes/db/data/base/5/17890
supabase/volumes/db/data/base/5/17889
supabase/volumes/db/data/base/5/17888
supabase/volumes/db/data/base/5/17887
supabase/volumes/db/data/base/5/17882
supabase/volumes/db/data/base/5/17880
supabase/volumes/db/data/base/5/17869
supabase/volumes/db/data/base/5/17867
supabase/volumes/db/data/base/5/17866
supabase/volumes/db/data/base/5/17865
supabase/volumes/db/data/base/5/17864
supabase/volumes/db/data/base/5/17862
supabase/volumes/db/data/base/5/17857
supabase/volumes/db/data/base/5/17847
supabase/volumes/db/data/base/5/17846
supabase/volumes/db/data/base/5/17845
supabase/volumes/db/data/base/5/17844
supabase/volumes/db/data/base/5/17843
supabase/volumes/db/data/base/5/17840
supabase/volumes/db/data/base/5/17838
supabase/volumes/db/data/base/5/17836
supabase/volumes/db/data/base/5/17835
supabase/volumes/db/data/base/5/17823
supabase/volumes/db/data/base/5/17819
supabase/volumes/db/data/base/5/17761
supabase/volumes/db/data/base/5/17760
supabase/volumes/db/data/base/5/17758
supabase/volumes/db/data/base/5/17756
supabase/volumes/db/data/base/5/17749
supabase/volumes/db/data/base/5/17744
supabase/volumes/db/data/base/5/17687
supabase/volumes/db/data/base/5/17684
supabase/volumes/db/data/base/5/17677
supabase/volumes/db/data/base/5/17675
supabase/volumes/db/data/base/5/17674
supabase/volumes/db/data/base/5/17673
supabase/volumes/db/data/base/5/17666
supabase/volumes/db/data/base/5/17659
supabase/volumes/db/data/base/5/17658
supabase/volumes/db/data/base/5/17657
supabase/volumes/db/data/base/5/17654
supabase/volumes/db/data/base/5/17650
supabase/volumes/db/data/base/5/17649
supabase/volumes/db/data/base/5/17648
supabase/volumes/db/data/base/5/17647
supabase/volumes/db/data/base/5/17646
supabase/volumes/db/data/base/5/17641
supabase/volumes/db/data/base/5/17638
supabase/volumes/db/data/base/5/17626
supabase/volumes/db/data/base/5/17623
supabase/volumes/db/data/base/5/17621
supabase/volumes/db/data/base/5/17616_fsm
supabase/volumes/db/data/base/5/17616
supabase/volumes/db/data/base/5/17614
supabase/volumes/db/data/base/5/17611
supabase/volumes/db/data/base/5/17609
supabase/volumes/db/data/base/5/17604_fsm
supabase/volumes/db/data/base/5/17604
supabase/volumes/db/data/base/5/17602
supabase/volumes/db/data/base/5/17599
supabase/volumes/db/data/base/5/17590
supabase/volumes/db/data/base/5/17587
supabase/volumes/db/data/base/5/17585
supabase/volumes/db/data/base/5/17580_fsm
supabase/volumes/db/data/base/5/17580
supabase/volumes/db/data/base/5/17578
supabase/volumes/db/data/base/5/17575
supabase/volumes/db/data/base/5/17566
supabase/volumes/db/data/base/5/17563
supabase/volumes/db/data/base/5/17554
supabase/volumes/db/data/base/5/17551
supabase/volumes/db/data/base/5/17549
supabase/volumes/db/data/base/5/17544_fsm
supabase/volumes/db/data/base/5/17544
supabase/volumes/db/data/base/5/17542
supabase/volumes/db/data/base/5/17539
supabase/volumes/db/data/base/5/17537
supabase/volumes/db/data/base/5/17532_fsm
supabase/volumes/db/data/base/5/17532
supabase/volumes/db/data/base/5/17530
supabase/volumes/db/data/base/5/17527
supabase/volumes/db/data/base/5/17508
supabase/volumes/db/data/base/5/17499
supabase/volumes/db/data/base/5/17482
supabase/volumes/db/data/base/5/17476
supabase/volumes/db/data/base/5/17475
supabase/volumes/db/data/base/5/17465
supabase/volumes/db/data/base/5/17464
supabase/volumes/db/data/base/5/17437
supabase/volumes/db/data/base/5/17435
supabase/volumes/db/data/base/5/17434
supabase/volumes/db/data/base/5/17427
supabase/volumes/db/data/base/5/17421
supabase/volumes/db/data/base/5/17420
supabase/volumes/db/data/base/5/17401
supabase/volumes/db/data/base/5/17376
supabase/volumes/db/data/base/5/17373
supabase/volumes/db/data/base/5/17372
supabase/volumes/db/data/base/5/17360
supabase/volumes/db/data/base/5/17356
supabase/volumes/db/data/base/5/17355
supabase/volumes/db/data/base/5/17350
supabase/volumes/db/data/base/5/17336
supabase/volumes/db/data/base/5/17325
supabase/volumes/db/data/base/5/17319
supabase/volumes/db/data/base/5/17318
supabase/volumes/db/data/base/5/17302
supabase/volumes/db/data/base/5/17277
supabase/volumes/db/data/base/5/17272
supabase/volumes/db/data/base/5/17252
supabase/volumes/db/data/base/5/17240
supabase/volumes/db/data/base/5/17226
supabase/volumes/db/data/base/5/17225
supabase/volumes/db/data/base/5/17222
supabase/volumes/db/data/base/5/17220
supabase/volumes/db/data/base/5/17216
supabase/volumes/db/data/base/5/17215
supabase/volumes/db/data/base/5/17212
supabase/volumes/db/data/base/5/17211
supabase/volumes/db/data/base/5/17210
supabase/volumes/db/data/base/5/17209
supabase/volumes/db/data/base/5/17208
supabase/volumes/db/data/base/5/17203
supabase/volumes/db/data/base/5/17192
supabase/volumes/db/data/base/5/17163
supabase/volumes/db/data/base/5/17156
supabase/volumes/db/data/base/5/17137
supabase/volumes/db/data/base/5/17122
supabase/volumes/db/data/base/5/17110
supabase/volumes/db/data/base/5/17109
supabase/volumes/db/data/base/5/17108
supabase/volumes/db/data/base/5/17095
supabase/volumes/db/data/base/5/17094
supabase/volumes/db/data/base/5/17093
supabase/volumes/db/data/base/5/17092
supabase/volumes/db/data/base/5/17085
supabase/volumes/db/data/base/5/17081
supabase/volumes/db/data/base/5/17080
supabase/volumes/db/data/base/5/17078
supabase/volumes/db/data/base/5/17072
supabase/volumes/db/data/base/5/17071
supabase/volumes/db/data/base/5/17069
supabase/volumes/db/data/base/5/17066
supabase/volumes/db/data/base/5/17058
supabase/volumes/db/data/base/5/16570
supabase/volumes/db/data/base/5/16557
supabase/volumes/db/data/base/5/16555
supabase/volumes/db/data/base/5/16551
supabase/volumes/db/data/base/5/16546
supabase/volumes/db/data/base/5/16545
supabase/volumes/db/data/base/5/16533
supabase/volumes/db/data/base/5/16532
supabase/volumes/db/data/base/5/16531
supabase/volumes/db/data/base/5/16524
supabase/volumes/db/data/base/5/16523
supabase/volumes/db/data/base/5/16516
supabase/volumes/db/data/base/5/16515
supabase/volumes/db/data/base/5/16514
supabase/volumes/db/data/base/5/16509
supabase/volumes/db/data/base/5/16499
supabase/volumes/db/data/base/5/16496
supabase/volumes/db/data/base/5/16495
supabase/volumes/db/data/base/5/16493
supabase/volumes/db/data/base/5/16488
supabase/volumes/db/data/base/5/16480
supabase/volumes/db/data/base/5/16479
supabase/volumes/db/data/base/5/16478
supabase/volumes/db/data/base/5/16476
supabase/volumes/db/data/base/5/16470
supabase/volumes/db/data/base/5/16469
supabase/volumes/db/data/base/5/16468
supabase/volumes/db/data/base/5/16467
supabase/volumes/db/data/base/5/16465
supabase/volumes/db/data/base/5/16463
supabase/volumes/db/data/base/5/16462
supabase/volumes/db/data/base/5/16461
supabase/volumes/db/data/base/5/16458
supabase/volumes/db/data/base/5/1259_vm
supabase/volumes/db/data/base/5/1259_fsm
supabase/volumes/db/data/base/5/1259
supabase/volumes/db/data/base/5/1255_fsm
supabase/volumes/db/data/base/5/1255
supabase/volumes/db/data/base/5/1249_vm
supabase/volumes/db/data/base/5/1249_fsm
supabase/volumes/db/data/base/5/1249
supabase/volumes/db/data/base/5/1247_fsm
supabase/volumes/db/data/base/5/1247
supabase/volumes/db/data/base/1/2841
supabase/volumes/db/data/base/1/2840_vm
supabase/volumes/db/data/base/1/2840_fsm
supabase/volumes/db/data/base/1/2840
supabase/volumes/db/data/base/1/2696
supabase/volumes/db/data/base/1/2619_vm
supabase/volumes/db/data/base/1/2619_fsm
supabase/volumes/db/data/base/1/2619
supabase/volumes/db/data/base/1/1259

View File

@ -7,25 +7,25 @@
- https://nextjs.org/docs
- https://supabase.com/docs/guides/self-hosting/docker
### Running With Docker
### Running Backend
1) Open your terminal and navigate to the root of the git repository.
2) Make sure that docker and docker compose are installed.
3) Run `docker-compose --env-file ./docker.env up` which will start up OwnCast, AppWrite, and the UI.
#### MailDev
http://localhost:1080
This is where all mail being sent shows up from the application for developers.
#### OwnCast
http://localhost:8080/
Configuration is done through the Owncast administration page located on your server under /admin. The login username is admin and the password is your stream key, the default being abc123.
#### Supabase
http://localhost:8000/
You will need to register and sign up, the first account on the appwrite instance will be the admin account.çConfiguration is done through the Owncast administration page located on your server under /admin. The login username is admin and the password is your stream key, the default being abc123.
#### UI
http://localhost:3000
### Running Without Docker
### Running UI
1) Open your terminal and navigate to the root folder of the git repository.
2) Run the command `npm update`.
3) Once the depedencies are pulled and installed you can run the command `npm run dev` to run the application in development mode.
4) Open http://localhost:3000/
4) Open http://localhost:3000/

View File

@ -0,0 +1,19 @@
import { createClient } from "@/utils/supabase/server";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
// The `/auth/callback` route is required for the server-side auth flow implemented
// by the SSR package. It exchanges an auth code for the user's session.
// https://supabase.com/docs/guides/auth/server-side/nextjs
const requestUrl = new URL(request.url);
const code = requestUrl.searchParams.get("code");
const origin = requestUrl.origin;
if (code) {
const supabase = createClient();
await supabase.auth.exchangeCodeForSession(code);
}
// URL to redirect to after sign up process completes
return NextResponse.redirect(`${origin}/protected`);
}

BIN
app/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

42
app/globals.css Normal file
View File

@ -0,0 +1,42 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
--background: 200 20% 98%;
--btn-background: 200 10% 91%;
--btn-background-hover: 200 10% 89%;
--foreground: 200 50% 3%;
}
@media (prefers-color-scheme: dark) {
:root {
--background: 200 50% 3%;
--btn-background: 200 10% 9%;
--btn-background-hover: 200 10% 12%;
--foreground: 200 20% 96%;
}
}
}
@layer base {
* {
@apply border-foreground/20;
}
}
.animate-in {
animation: animateIn 0.3s ease 0.15s both;
}
@keyframes animateIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}

28
app/layout.tsx Normal file
View File

@ -0,0 +1,28 @@
import { GeistSans } from "geist/font/sans";
import "./globals.css";
const defaultUrl = process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: "http://localhost:3000";
export const metadata = {
metadataBase: new URL(defaultUrl),
title: "Next.js and Supabase Starter Kit",
description: "The fastest way to build apps with Next.js and Supabase",
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en" className={GeistSans.className}>
<body className="bg-background text-foreground">
<main className="min-h-screen flex flex-col items-center">
{children}
</main>
</body>
</html>
);
}

119
app/login/page.tsx Normal file
View File

@ -0,0 +1,119 @@
import Link from "next/link";
import { headers } from "next/headers";
import { createClient } from "@/utils/supabase/server";
import { redirect } from "next/navigation";
import { SubmitButton } from "./submit-button";
export default function Login({
searchParams,
}: {
searchParams: { message: string };
}) {
const signIn = async (formData: FormData) => {
"use server";
const email = formData.get("email") as string;
const password = formData.get("password") as string;
const supabase = createClient();
const { error } = await supabase.auth.signInWithPassword({
email,
password,
});
if (error) {
return redirect("/login?message=Could not authenticate user");
}
return redirect("/protected");
};
const signUp = async (formData: FormData) => {
"use server";
const origin = headers().get("origin");
const email = formData.get("email") as string;
const password = formData.get("password") as string;
const supabase = createClient();
const { error } = await supabase.auth.signUp({
email,
password,
options: {
emailRedirectTo: `${origin}/auth/callback`,
},
});
if (error) {
return redirect("/login?message=Could not authenticate user");
}
return redirect("/login?message=Check email to continue sign in process");
};
return (
<div className="flex-1 flex flex-col w-full px-8 sm:max-w-md justify-center gap-2">
<Link
href="/"
className="absolute left-8 top-8 py-2 px-4 rounded-md no-underline text-foreground bg-btn-background hover:bg-btn-background-hover flex items-center group text-sm"
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="mr-2 h-4 w-4 transition-transform group-hover:-translate-x-1"
>
<polyline points="15 18 9 12 15 6" />
</svg>{" "}
Back
</Link>
<form className="animate-in flex-1 flex flex-col w-full justify-center gap-2 text-foreground">
<label className="text-md" htmlFor="email">
Email
</label>
<input
className="rounded-md px-4 py-2 bg-inherit border mb-6"
name="email"
placeholder="you@example.com"
required
/>
<label className="text-md" htmlFor="password">
Password
</label>
<input
className="rounded-md px-4 py-2 bg-inherit border mb-6"
type="password"
name="password"
placeholder="••••••••"
required
/>
<SubmitButton
formAction={signIn}
className="bg-green-700 rounded-md px-4 py-2 text-foreground mb-2"
pendingText="Signing In..."
>
Sign In
</SubmitButton>
<SubmitButton
formAction={signUp}
className="border border-foreground/20 rounded-md px-4 py-2 text-foreground mb-2"
pendingText="Signing Up..."
>
Sign Up
</SubmitButton>
{searchParams?.message && (
<p className="mt-4 p-4 bg-foreground/10 text-foreground text-center">
{searchParams.message}
</p>
)}
</form>
</div>
);
}

View File

@ -0,0 +1,20 @@
"use client";
import { useFormStatus } from "react-dom";
import { type ComponentProps } from "react";
type Props = ComponentProps<"button"> & {
pendingText?: string;
};
export function SubmitButton({ children, pendingText, ...props }: Props) {
const { pending, action } = useFormStatus();
const isPending = pending && action === props.formAction;
return (
<button {...props} type="submit" aria-disabled={pending}>
{isPending ? pendingText : children}
</button>
);
}

BIN
app/opengraph-image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

54
app/page.tsx Normal file
View File

@ -0,0 +1,54 @@
import DeployButton from "../components/DeployButton";
import AuthButton from "../components/AuthButton";
import { createClient } from "@/utils/supabase/server";
import ConnectSupabaseSteps from "@/components/tutorial/ConnectSupabaseSteps";
import SignUpUserSteps from "@/components/tutorial/SignUpUserSteps";
import Header from "@/components/Header";
export default async function Index() {
const canInitSupabaseClient = () => {
// This function is just for the interactive tutorial.
// Feel free to remove it once you have Supabase connected.
try {
createClient();
return true;
} catch (e) {
return false;
}
};
const isSupabaseConnected = canInitSupabaseClient();
return (
<div className="flex-1 w-full flex flex-col gap-20 items-center">
<nav className="w-full flex justify-center border-b border-b-foreground/10 h-16">
<div className="w-full max-w-4xl flex justify-between items-center p-3 text-sm">
<DeployButton />
{isSupabaseConnected && <AuthButton />}
</div>
</nav>
<div className="animate-in flex-1 flex flex-col gap-20 opacity-0 max-w-4xl px-3">
<Header />
<main className="flex-1 flex flex-col gap-6">
<h2 className="font-bold text-4xl mb-4">Next steps</h2>
{isSupabaseConnected ? <SignUpUserSteps /> : <ConnectSupabaseSteps />}
</main>
</div>
<footer className="w-full border-t border-t-foreground/10 p-8 flex justify-center text-center text-xs">
<p>
Powered by{" "}
<a
href="https://supabase.com/?utm_source=create-next-app&utm_medium=template&utm_term=nextjs"
target="_blank"
className="font-bold hover:underline"
rel="noreferrer"
>
Supabase
</a>
</p>
</footer>
</div>
);
}

57
app/protected/page.tsx Normal file
View File

@ -0,0 +1,57 @@
import DeployButton from "@/components/DeployButton";
import AuthButton from "@/components/AuthButton";
import { createClient } from "@/utils/supabase/server";
import FetchDataSteps from "@/components/tutorial/FetchDataSteps";
import Header from "@/components/Header";
import { redirect } from "next/navigation";
export default async function ProtectedPage() {
const supabase = createClient();
const {
data: { user },
} = await supabase.auth.getUser();
if (!user) {
return redirect("/login");
}
return (
<div className="flex-1 w-full flex flex-col gap-20 items-center">
<div className="w-full">
<div className="py-6 font-bold bg-purple-950 text-center">
This is a protected page that you can only see as an authenticated
user
</div>
<nav className="w-full flex justify-center border-b border-b-foreground/10 h-16">
<div className="w-full max-w-4xl flex justify-between items-center p-3 text-sm">
<DeployButton />
<AuthButton />
</div>
</nav>
</div>
<div className="animate-in flex-1 flex flex-col gap-20 opacity-0 max-w-4xl px-3">
<Header />
<main className="flex-1 flex flex-col gap-6">
<h2 className="font-bold text-4xl mb-4">Next steps</h2>
<FetchDataSteps />
</main>
</div>
<footer className="w-full border-t border-t-foreground/10 p-8 flex justify-center text-center text-xs">
<p>
Powered by{" "}
<a
href="https://supabase.com/?utm_source=create-next-app&utm_medium=template&utm_term=nextjs"
target="_blank"
className="font-bold hover:underline"
rel="noreferrer"
>
Supabase
</a>
</p>
</footer>
</div>
);
}

BIN
app/twitter-image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

37
components/AuthButton.tsx Normal file
View File

@ -0,0 +1,37 @@
import { createClient } from "@/utils/supabase/server";
import Link from "next/link";
import { redirect } from "next/navigation";
export default async function AuthButton() {
const supabase = createClient();
const {
data: { user },
} = await supabase.auth.getUser();
const signOut = async () => {
"use server";
const supabase = createClient();
await supabase.auth.signOut();
return redirect("/login");
};
return user ? (
<div className="flex items-center gap-4">
Hey, {user.email}!
<form action={signOut}>
<button className="py-2 px-4 rounded-md no-underline bg-btn-background hover:bg-btn-background-hover">
Logout
</button>
</form>
</div>
) : (
<Link
href="/login"
className="py-2 px-3 flex rounded-md no-underline bg-btn-background hover:bg-btn-background-hover"
>
Login
</Link>
);
}

View File

@ -0,0 +1,23 @@
export default function DeployButton() {
return (
<a
className="py-2 px-3 flex rounded-md no-underline hover:bg-btn-background-hover border"
href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fwith-supabase&project-name=nextjs-with-supabase&repository-name=nextjs-with-supabase&demo-title=nextjs-with-supabase&demo-description=This%20starter%20configures%20Supabase%20Auth%20to%20use%20cookies%2C%20making%20the%20user's%20session%20available%20throughout%20the%20entire%20Next.js%20app%20-%20Client%20Components%2C%20Server%20Components%2C%20Route%20Handlers%2C%20Server%20Actions%20and%20Middleware.&demo-url=https%3A%2F%2Fdemo-nextjs-with-supabase.vercel.app%2F&external-id=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fwith-supabase&demo-image=https%3A%2F%2Fdemo-nextjs-with-supabase.vercel.app%2Fopengraph-image.png&integration-ids=oac_VqOgBHqhEoFTPzGkPd7L0iH6"
target="_blank"
rel="noreferrer"
>
<svg
aria-label="Vercel logomark"
role="img"
viewBox="0 0 74 64"
className="h-4 w-4 mr-2"
>
<path
d="M37.5896 0.25L74.5396 64.25H0.639648L37.5896 0.25Z"
fill="currentColor"
></path>
</svg>
Deploy to Vercel
</a>
);
}

44
components/Header.tsx Normal file
View File

@ -0,0 +1,44 @@
import NextLogo from "./NextLogo";
import SupabaseLogo from "./SupabaseLogo";
export default function Header() {
return (
<div className="flex flex-col gap-16 items-center">
<div className="flex gap-8 justify-center items-center">
<a
href="https://supabase.com/?utm_source=create-next-app&utm_medium=template&utm_term=nextjs"
target="_blank"
rel="noreferrer"
>
<SupabaseLogo />
</a>
<span className="border-l rotate-45 h-6" />
<a href="https://nextjs.org/" target="_blank" rel="noreferrer">
<NextLogo />
</a>
</div>
<h1 className="sr-only">Supabase and Next.js Starter Template</h1>
<p className="text-3xl lg:text-4xl !leading-tight mx-auto max-w-xl text-center">
The fastest way to build apps with{" "}
<a
href="https://supabase.com/?utm_source=create-next-app&utm_medium=template&utm_term=nextjs"
target="_blank"
className="font-bold hover:underline"
rel="noreferrer"
>
Supabase
</a>{" "}
and{" "}
<a
href="https://nextjs.org/"
target="_blank"
className="font-bold hover:underline"
rel="noreferrer"
>
Next.js
</a>
</p>
<div className="w-full p-[1px] bg-gradient-to-r from-transparent via-foreground/10 to-transparent my-8" />
</div>
);
}

46
components/NextLogo.tsx Normal file
View File

@ -0,0 +1,46 @@
export default function NextLogo() {
return (
<svg
aria-label="Next.js logotype"
height="68"
role="img"
viewBox="0 0 394 79"
width="100"
>
<path
d="M261.919 0.0330722H330.547V12.7H303.323V79.339H289.71V12.7H261.919V0.0330722Z"
fill="currentColor"
/>
<path
d="M149.052 0.0330722V12.7H94.0421V33.0772H138.281V45.7441H94.0421V66.6721H149.052V79.339H80.43V12.7H80.4243V0.0330722H149.052Z"
fill="currentColor"
/>
<path
d="M183.32 0.0661486H165.506L229.312 79.3721H247.178L215.271 39.7464L247.127 0.126654L229.312 0.154184L206.352 28.6697L183.32 0.0661486Z"
fill="currentColor"
/>
<path
d="M201.6 56.7148L192.679 45.6229L165.455 79.4326H183.32L201.6 56.7148Z"
fill="currentColor"
/>
<path
clipRule="evenodd"
d="M80.907 79.339L17.0151 0H0V79.3059H13.6121V16.9516L63.8067 79.339H80.907Z"
fill="currentColor"
fillRule="evenodd"
/>
<path
d="M333.607 78.8546C332.61 78.8546 331.762 78.5093 331.052 77.8186C330.342 77.1279 329.991 76.2917 330 75.3011C329.991 74.3377 330.342 73.5106 331.052 72.8199C331.762 72.1292 332.61 71.7838 333.607 71.7838C334.566 71.7838 335.405 72.1292 336.115 72.8199C336.835 73.5106 337.194 74.3377 337.204 75.3011C337.194 75.9554 337.028 76.5552 336.696 77.0914C336.355 77.6368 335.922 78.064 335.377 78.373C334.842 78.6911 334.252 78.8546 333.607 78.8546Z"
fill="currentColor"
/>
<path
d="M356.84 45.4453H362.872V68.6846C362.863 70.8204 362.401 72.6472 361.498 74.1832C360.585 75.7191 359.321 76.8914 357.698 77.7185C356.084 78.5364 354.193 78.9546 352.044 78.9546C350.079 78.9546 348.318 78.6001 346.75 77.9094C345.182 77.2187 343.937 76.1826 343.024 74.8193C342.101 73.456 341.649 71.7565 341.649 69.7207H347.691C347.7 70.6114 347.903 71.3838 348.29 72.0291C348.677 72.6744 349.212 73.1651 349.895 73.5105C350.586 73.8559 351.38 74.0286 352.274 74.0286C353.243 74.0286 354.073 73.8286 354.746 73.4196C355.419 73.0197 355.936 72.4199 356.296 71.6201C356.646 70.8295 356.831 69.8479 356.84 68.6846V45.4453Z"
fill="currentColor"
/>
<path
d="M387.691 54.5338C387.544 53.1251 386.898 52.0254 385.773 51.2438C384.638 50.4531 383.172 50.0623 381.373 50.0623C380.11 50.0623 379.022 50.2532 378.118 50.6258C377.214 51.0075 376.513 51.5164 376.033 52.1617C375.554 52.807 375.314 53.5432 375.295 54.3703C375.295 55.061 375.461 55.6608 375.784 56.1607C376.107 56.6696 376.54 57.0968 377.103 57.4422C377.656 57.7966 378.274 58.0874 378.948 58.3237C379.63 58.56 380.313 58.76 380.995 58.9236L384.14 59.6961C385.404 59.9869 386.631 60.3778 387.802 60.8776C388.973 61.3684 390.034 61.9955 390.965 62.7498C391.897 63.5042 392.635 64.413 393.179 65.4764C393.723 66.5397 394 67.7848 394 69.2208C394 71.1566 393.502 72.8562 392.496 74.3285C391.491 75.7917 390.043 76.9369 388.143 77.764C386.252 78.582 383.965 79 381.272 79C378.671 79 376.402 78.6002 374.493 77.8004C372.575 77.0097 371.08 75.8463 370.001 74.3194C368.922 72.7926 368.341 70.9294 368.258 68.7391H374.235C374.318 69.8842 374.687 70.8386 375.314 71.6111C375.95 72.3745 376.78 72.938 377.795 73.3197C378.819 73.6923 379.962 73.8832 381.226 73.8832C382.545 73.8832 383.707 73.6832 384.712 73.2924C385.708 72.9016 386.492 72.3564 387.055 71.6475C387.627 70.9476 387.913 70.1206 387.922 69.1754C387.913 68.312 387.654 67.5939 387.156 67.0304C386.649 66.467 385.948 65.9944 385.053 65.6127C384.15 65.231 383.098 64.8856 381.899 64.5857L378.081 63.6223C375.323 62.9225 373.137 61.8592 371.541 60.4323C369.937 59.0054 369.143 57.115 369.143 54.7429C369.143 52.798 369.678 51.0894 370.758 49.6261C371.827 48.1629 373.294 47.0268 375.148 46.2179C377.011 45.4 379.114 45 381.456 45C383.836 45 385.92 45.4 387.719 46.2179C389.517 47.0268 390.929 48.1538 391.952 49.5897C392.976 51.0257 393.511 52.6707 393.539 54.5338H387.691Z"
fill="currentColor"
/>
</svg>
);
}

102
components/SupabaseLogo.tsx Normal file
View File

@ -0,0 +1,102 @@
export default function SupabaseLogo() {
return (
<svg
aria-label="Supabase logo"
width="140"
height="30"
viewBox="0 0 115 23"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<g clipPath="url(#clip0_4671_51136)">
<g clipPath="url(#clip1_4671_51136)">
<path
d="M13.4028 21.8652C12.8424 22.5629 11.7063 22.1806 11.6928 21.2898L11.4954 8.25948H20.3564C21.9614 8.25948 22.8565 10.0924 21.8585 11.3353L13.4028 21.8652Z"
fill="url(#paint0_linear_4671_51136)"
/>
<path
d="M13.4028 21.8652C12.8424 22.5629 11.7063 22.1806 11.6928 21.2898L11.4954 8.25948H20.3564C21.9614 8.25948 22.8565 10.0924 21.8585 11.3353L13.4028 21.8652Z"
fill="url(#paint1_linear_4671_51136)"
fillOpacity="0.2"
/>
<path
d="M9.79895 0.89838C10.3593 0.200591 11.4954 0.582929 11.5089 1.47383L11.5955 14.5041H2.84528C1.24026 14.5041 0.345103 12.6711 1.34316 11.4283L9.79895 0.89838Z"
fill="#3ECF8E"
/>
</g>
<path
d="M30.5894 13.3913C30.7068 14.4766 31.7052 16.3371 34.6026 16.3371C37.1279 16.3371 38.3418 14.7479 38.3418 13.1976C38.3418 11.8022 37.3824 10.6588 35.4836 10.2712L34.1131 9.98049C33.5846 9.88359 33.2323 9.5929 33.2323 9.12777C33.2323 8.58512 33.7804 8.17818 34.4656 8.17818C35.5618 8.17818 35.9729 8.89521 36.0513 9.45725L38.2243 8.97275C38.1069 7.94561 37.1867 6.22083 34.446 6.22083C32.3709 6.22083 30.844 7.63555 30.844 9.34094C30.844 10.6781 31.6856 11.7828 33.5454 12.1898L34.8179 12.4805C35.5618 12.6355 35.8555 12.9844 35.8555 13.4107C35.8555 13.9146 35.4444 14.3603 34.583 14.3603C33.4476 14.3603 32.8797 13.6626 32.8212 12.9068L30.5894 13.3913Z"
fill="currentColor"
/>
<path
d="M46.6623 16.0464H49.1486C49.1094 15.717 49.0506 15.0581 49.0506 14.3216V6.51154H46.4468V12.0542C46.4468 13.1588 45.7813 13.934 44.6263 13.934C43.4126 13.934 42.8643 13.0813 42.8643 12.0154V6.51154H40.2606V12.5387C40.2606 14.6123 41.5918 16.2984 43.9215 16.2984C44.9393 16.2984 46.0556 15.9108 46.5841 15.0193C46.5841 15.4069 46.6231 15.8526 46.6623 16.0464Z"
fill="currentColor"
/>
<path
d="M54.433 19.7286V15.1162C54.9027 15.7558 55.8817 16.279 57.213 16.279C59.9341 16.279 61.7545 14.1472 61.7545 11.2596C61.7545 8.43021 60.1298 6.29842 57.3108 6.29842C55.8623 6.29842 54.7855 6.93792 54.3548 7.67439V6.51159H51.8295V19.7286H54.433ZM59.19 11.279C59.19 12.9845 58.133 13.9728 56.8017 13.9728C55.4708 13.9728 54.394 12.9651 54.394 11.279C54.394 9.59299 55.4708 8.6046 56.8017 8.6046C58.133 8.6046 59.19 9.59299 59.19 11.279Z"
fill="currentColor"
/>
<path
d="M63.229 13.4495C63.229 14.9417 64.4818 16.3177 66.5375 16.3177C67.9662 16.3177 68.8865 15.6588 69.3758 14.9029C69.3758 15.2712 69.4149 15.7944 69.4737 16.0464H71.862C71.8033 15.7169 71.7449 15.0386 71.7449 14.5348V9.84482C71.7449 7.92622 70.6093 6.22083 67.5555 6.22083C64.9713 6.22083 63.5811 7.86807 63.4248 9.36033L65.7347 9.84482C65.8131 9.0115 66.4395 8.29445 67.5747 8.29445C68.6713 8.29445 69.1998 8.85646 69.1998 9.53475C69.1998 9.86421 69.0238 10.1355 68.4755 10.2131L66.1068 10.5619C64.5015 10.7945 63.229 11.744 63.229 13.4495ZM67.0854 14.3991C66.2438 14.3991 65.8325 13.8565 65.8325 13.2945C65.8325 12.558 66.361 12.1898 67.0268 12.0929L69.1998 11.7634V12.1898C69.1998 13.8759 68.1818 14.3991 67.0854 14.3991Z"
fill="currentColor"
/>
<path
d="M76.895 16.0465V14.8837C77.4038 15.6976 78.4217 16.279 79.7531 16.279C82.4941 16.279 84.2951 14.1278 84.2951 11.2403C84.2951 8.4108 82.6701 6.25965 79.851 6.25965C78.4217 6.25965 77.3648 6.8798 76.934 7.55806V2.01546H74.3696V16.0465H76.895ZM81.6911 11.2596C81.6911 13.0038 80.6341 13.9728 79.3028 13.9728C77.9912 13.9728 76.895 12.9845 76.895 11.2596C76.895 9.51543 77.9912 8.56584 79.3028 8.56584C80.6341 8.56584 81.6911 9.51543 81.6911 11.2596Z"
fill="currentColor"
/>
<path
d="M85.7692 13.4495C85.7692 14.9417 87.022 16.3177 89.0776 16.3177C90.5065 16.3177 91.4269 15.6588 91.916 14.9029C91.916 15.2712 91.9554 15.7944 92.014 16.0464H94.4023C94.3439 15.7169 94.2851 15.0386 94.2851 14.5348V9.84482C94.2851 7.92622 93.1495 6.22083 90.0955 6.22083C87.5115 6.22083 86.1216 7.86807 85.965 9.36033L88.2747 9.84482C88.3533 9.0115 88.9798 8.29445 90.1149 8.29445C91.2115 8.29445 91.74 8.85646 91.74 9.53475C91.74 9.86421 91.5638 10.1355 91.0156 10.2131L88.647 10.5619C87.0418 10.7945 85.7692 11.744 85.7692 13.4495ZM89.6258 14.3991C88.784 14.3991 88.3727 13.8565 88.3727 13.2945C88.3727 12.558 88.9012 12.1898 89.5671 12.0929L91.74 11.7634V12.1898C91.74 13.8759 90.722 14.3991 89.6258 14.3991Z"
fill="currentColor"
/>
<path
d="M96.087 13.3913C96.2042 14.4766 97.2028 16.3371 100.1 16.3371C102.626 16.3371 103.839 14.7479 103.839 13.1976C103.839 11.8022 102.88 10.6588 100.981 10.2712L99.6105 9.98049C99.082 9.88359 98.7299 9.5929 98.7299 9.12777C98.7299 8.58512 99.2778 8.17818 99.963 8.17818C101.06 8.17818 101.471 8.89521 101.549 9.45725L103.722 8.97275C103.604 7.94561 102.684 6.22083 99.9436 6.22083C97.8683 6.22083 96.3416 7.63555 96.3416 9.34094C96.3416 10.6781 97.183 11.7828 99.043 12.1898L100.316 12.4805C101.06 12.6355 101.353 12.9844 101.353 13.4107C101.353 13.9146 100.942 14.3603 100.081 14.3603C98.9451 14.3603 98.3776 13.6626 98.3188 12.9068L96.087 13.3913Z"
fill="currentColor"
/>
<path
d="M107.794 10.1937C107.852 9.32158 108.596 8.31381 109.947 8.31381C111.435 8.31381 112.062 9.24406 112.101 10.1937H107.794ZM112.355 12.6743C112.042 13.527 111.376 14.1278 110.163 14.1278C108.87 14.1278 107.794 13.2169 107.735 11.9573H114.626C114.626 11.9184 114.665 11.5309 114.665 11.1626C114.665 8.10064 112.884 6.22083 109.908 6.22083C107.441 6.22083 105.17 8.19753 105.17 11.2402C105.17 14.4572 107.5 16.3371 110.143 16.3371C112.512 16.3371 114.039 14.9611 114.528 13.3138L112.355 12.6743Z"
fill="currentColor"
/>
</g>
<defs>
<linearGradient
id="paint0_linear_4671_51136"
x1="11.4954"
y1="11.1486"
x2="19.3439"
y2="14.4777"
gradientUnits="userSpaceOnUse"
>
<stop stopColor="#249361" />
<stop offset="1" stopColor="#3ECF8E" />
</linearGradient>
<linearGradient
id="paint1_linear_4671_51136"
x1="8.00382"
y1="6.42177"
x2="11.5325"
y2="13.1398"
gradientUnits="userSpaceOnUse"
>
<stop />
<stop offset="1" stopOpacity="0" />
</linearGradient>
<clipPath id="clip0_4671_51136">
<rect
width="113.85"
height="21.8943"
fill="currentColor"
transform="translate(0.922119 0.456161)"
/>
</clipPath>
<clipPath id="clip1_4671_51136">
<rect
width="21.3592"
height="21.8943"
fill="currentColor"
transform="translate(0.919006 0.497101)"
/>
</clipPath>
</defs>
</svg>
);
}

View File

@ -0,0 +1,58 @@
"use client";
import { useState } from "react";
const CopyIcon = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
</svg>
);
const CheckIcon = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<polyline points="20 6 9 17 4 12"></polyline>
</svg>
);
export default function Code({ code }: { code: string }) {
const [icon, setIcon] = useState(CopyIcon);
const copy = async () => {
await navigator?.clipboard?.writeText(code);
setIcon(CheckIcon);
setTimeout(() => setIcon(CopyIcon), 2000);
};
return (
<pre className="bg-foreground/5 rounded-md p-8 my-8 relative">
<button
onClick={copy}
className="absolute top-4 right-4 p-2 rounded-md bg-foreground/5 hover:bg-foreground/10"
>
{icon}
</button>
<code>{code}</code>
</pre>
);
}

View File

@ -0,0 +1,62 @@
import Step from "./Step";
export default function ConnectSupabaseSteps() {
return (
<ol className="flex flex-col gap-6">
<Step title="Create Supabase project">
<p>
Head over to{" "}
<a
href="https://app.supabase.com/project/_/settings/api"
target="_blank"
className="font-bold hover:underline text-foreground/80"
rel="noreferrer"
>
database.new
</a>{" "}
and create a new Supabase project.
</p>
</Step>
<Step title="Declare environment variables">
<p>
Rename the{" "}
<span className="px-2 py-1 rounded-md bg-foreground/20 text-foreground/80">
.env.example
</span>{" "}
file in your Next.js app to{" "}
<span className="px-2 py-1 rounded-md bg-foreground/20 text-foreground/80">
.env.local
</span>{" "}
and populate with values from{" "}
<a
href="https://app.supabase.com/project/_/settings/api"
target="_blank"
className="font-bold hover:underline text-foreground/80"
rel="noreferrer"
>
your Supabase project's API Settings
</a>
.
</p>
</Step>
<Step title="Restart your Next.js development server">
<p>
You may need to quit your Next.js development server and run{" "}
<span className="px-2 py-1 rounded-md bg-foreground/20 text-foreground/80">
npm run dev
</span>{" "}
again to load the new environment variables.
</p>
</Step>
<Step title="Refresh the page">
<p>
You may need to refresh the page for Next.js to load the new
environment variables.
</p>
</Step>
</ol>
);
}

View File

@ -0,0 +1,99 @@
import Step from "./Step";
import Code from "./Code";
const create = `
create table notes (
id bigserial primary key,
title text
);
insert into notes(title)
values
('Today I created a Supabase project.'),
('I added some data and queried it from Next.js.'),
('It was awesome!');
`.trim();
const server = `
import { createClient } from '@/utils/supabase/server'
export default async function Page() {
const supabase = createClient()
const { data: notes } = await supabase.from('notes').select()
return <pre>{JSON.stringify(notes, null, 2)}</pre>
}
`.trim();
const client = `
'use client'
import { createClient } from '@/utils/supabase/client'
import { useEffect, useState } from 'react'
export default function Page() {
const [notes, setNotes] = useState<any[] | null>(null)
const supabase = createClient()
useEffect(() => {
const getData = async () => {
const { data } = await supabase.from('notes').select()
setNotes(data)
}
getData()
}, [])
return <pre>{JSON.stringify(notes, null, 2)}</pre>
}
`.trim();
export default function FetchDataSteps() {
return (
<ol className="flex flex-col gap-6">
<Step title="Create some tables and insert some data">
<p>
Head over to the{" "}
<a
href="https://supabase.com/dashboard/project/_/editor"
className="font-bold hover:underline text-foreground/80"
target="_blank"
rel="noreferrer"
>
Table Editor
</a>{" "}
for your Supabase project to create a table and insert some example
data. If you're stuck for creativity, you can copy and paste the
following into the{" "}
<a
href="https://supabase.com/dashboard/project/_/sql/new"
className="font-bold hover:underline text-foreground/80"
target="_blank"
rel="noreferrer"
>
SQL Editor
</a>{" "}
and click RUN!
</p>
<Code code={create} />
</Step>
<Step title="Query Supabase data from Next.js">
<p>
To create a Supabase client and query data from an Async Server
Component, create a new page.tsx file at{" "}
<span className="px-2 py-1 rounded-md bg-foreground/20 text-foreground/80">
/app/notes/page.tsx
</span>{" "}
and add the following.
</p>
<Code code={server} />
<p>Alternatively, you can use a Client Component.</p>
<Code code={client} />
</Step>
<Step title="Build in a weekend and scale to millions!">
<p>You're ready to launch your product to the world! 🚀</p>
</Step>
</ol>
);
}

View File

@ -0,0 +1,22 @@
import Link from "next/link";
import Step from "./Step";
export default function SignUpUserSteps() {
return (
<ol className="flex flex-col gap-6">
<Step title="Sign up your first user">
<p>
Head over to the{" "}
<Link
href="/login"
className="font-bold hover:underline text-foreground/80"
>
Login
</Link>{" "}
page and sign up your first user. It's okay if this is just you for
now. Your awesome idea will have plenty of users later!
</p>
</Step>
</ol>
);
}

View File

@ -0,0 +1,24 @@
export default function Step({
title,
children,
}: {
title: string;
children: React.ReactNode;
}) {
return (
<li className="mx-4">
<input type="checkbox" id={title} className={`mr-2 peer`} />
<label
htmlFor={title}
className={`text-lg text-foreground/90 peer-checked:line-through font-semibold hover:cursor-pointer`}
>
{title}
</label>
<div
className={`mx-6 text-foreground/80 text-sm peer-checked:line-through`}
>
{children}
</div>
</li>
);
}

View File

@ -8,20 +8,29 @@ x-logging: &x-logging
include:
- "supabase/docker-compose.yml"
services:
neroshitron:
build:
context: .
restart: unless-stopped
ports:
- 3000:3000
# neroshitron:
# build:
# context: .
# restart: unless-stopped
# ports:
# - 3000:3000
owncast:
image: owncast/owncast:latest
restart: unless-stopped
ports:
- 8080:8080
volumes:
- ./data:/app/data
- ./data:/owncast/data
maildev:
image: maildev/maildev:latest
restart: unless-stopped
ports:
- 1080:1080
- 1025:1025
volumes:
- ./data:/maildev/data
volumes:
db-config:

View File

@ -55,8 +55,8 @@ MAILER_URLPATHS_EMAIL_CHANGE="/auth/v1/verify"
ENABLE_EMAIL_SIGNUP=true
ENABLE_EMAIL_AUTOCONFIRM=false
SMTP_ADMIN_EMAIL=admin@example.com
SMTP_HOST=supabase-mail
SMTP_PORT=2500
SMTP_HOST=maildev
SMTP_PORT=1025
SMTP_USER=fake_mail_user
SMTP_PASS=fake_mail_password
SMTP_SENDER_NAME=fake_sender

20
middleware.ts Normal file
View File

@ -0,0 +1,20 @@
import { type NextRequest } from "next/server";
import { updateSession } from "@/utils/supabase/middleware";
export async function middleware(request: NextRequest) {
return await updateSession(request);
}
export const config = {
matcher: [
/*
* Match all request paths except:
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
* - images - .svg, .png, .jpg, .jpeg, .gif, .webp
* Feel free to modify this pattern to include more paths.
*/
"/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
],
};

36
neroshitron/.gitignore vendored Normal file
View File

@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env*.local
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts

93
neroshitron/README.md Normal file
View File

@ -0,0 +1,93 @@
<a href="https://demo-nextjs-with-supabase.vercel.app/">
<img alt="Next.js and Supabase Starter Kit - the fastest way to build apps with Next.js and Supabase" src="https://demo-nextjs-with-supabase.vercel.app/opengraph-image.png">
<h1 align="center">Next.js and Supabase Starter Kit</h1>
</a>
<p align="center">
The fastest way to build apps with Next.js and Supabase
</p>
<p align="center">
<a href="#features"><strong>Features</strong></a> ·
<a href="#demo"><strong>Demo</strong></a> ·
<a href="#deploy-to-vercel"><strong>Deploy to Vercel</strong></a> ·
<a href="#clone-and-run-locally"><strong>Clone and run locally</strong></a> ·
<a href="#feedback-and-issues"><strong>Feedback and issues</strong></a>
<a href="#more-supabase-examples"><strong>More Examples</strong></a>
</p>
<br/>
## Features
- Works across the entire [Next.js](https://nextjs.org) stack
- App Router
- Pages Router
- Middleware
- Client
- Server
- It just works!
- supabase-ssr. A package to configure Supabase Auth to use cookies
- Styling with [Tailwind CSS](https://tailwindcss.com)
- Optional deployment with [Supabase Vercel Integration and Vercel deploy](#deploy-your-own)
- Environment variables automatically assigned to Vercel project
## Demo
You can view a fully working demo at [demo-nextjs-with-supabase.vercel.app](https://demo-nextjs-with-supabase.vercel.app/).
## Deploy to Vercel
Vercel deployment will guide you through creating a Supabase account and project.
After installation of the Supabase integration, all relevant environment variables will be assigned to the project so the deployment is fully functioning.
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fwith-supabase&project-name=nextjs-with-supabase&repository-name=nextjs-with-supabase&demo-title=nextjs-with-supabase&demo-description=This%20starter%20configures%20Supabase%20Auth%20to%20use%20cookies%2C%20making%20the%20user's%20session%20available%20throughout%20the%20entire%20Next.js%20app%20-%20Client%20Components%2C%20Server%20Components%2C%20Route%20Handlers%2C%20Server%20Actions%20and%20Middleware.&demo-url=https%3A%2F%2Fdemo-nextjs-with-supabase.vercel.app%2F&external-id=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fwith-supabase&demo-image=https%3A%2F%2Fdemo-nextjs-with-supabase.vercel.app%2Fopengraph-image.png&integration-ids=oac_VqOgBHqhEoFTPzGkPd7L0iH6)
The above will also clone the Starter kit to your GitHub, you can clone that locally and develop locally.
If you wish to just develop locally and not deploy to Vercel, [follow the steps below](#clone-and-run-locally).
## Clone and run locally
1. You'll first need a Supabase project which can be made [via the Supabase dashboard](https://database.new)
2. Create a Next.js app using the Supabase Starter template npx command
```bash
npx create-next-app -e with-supabase
```
3. Use `cd` to change into the app's directory
```bash
cd name-of-new-app
```
4. Rename `.env.local.example` to `.env.local` and update the following:
```
NEXT_PUBLIC_SUPABASE_URL=[INSERT SUPABASE PROJECT URL]
NEXT_PUBLIC_SUPABASE_ANON_KEY=[INSERT SUPABASE PROJECT API ANON KEY]
```
Both `NEXT_PUBLIC_SUPABASE_URL` and `NEXT_PUBLIC_SUPABASE_ANON_KEY` can be found in [your Supabase project's API settings](https://app.supabase.com/project/_/settings/api)
5. You can now run the Next.js local development server:
```bash
npm run dev
```
The starter kit should now be running on [localhost:3000](http://localhost:3000/).
> Check out [the docs for Local Development](https://supabase.com/docs/guides/getting-started/local-development) to also run Supabase locally.
## Feedback and issues
Please file feedback and issues over on the [Supabase GitHub org](https://github.com/supabase/supabase/issues/new/choose).
## More Supabase examples
- [Next.js Subscription Payments Starter](https://github.com/vercel/nextjs-subscription-payments)
- [Cookie-based Auth and the Next.js 13 App Router (free course)](https://youtube.com/playlist?list=PL5S4mPUpp4OtMhpnp93EFSo42iQ40XjbF)
- [Supabase Auth and the Next.js App Router](https://github.com/supabase/supabase/tree/master/examples/auth/nextjs)

5
next-env.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.

4
next.config.js Normal file
View File

@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
module.exports = nextConfig;

2013
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

26
package.json Normal file
View File

@ -0,0 +1,26 @@
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@supabase/ssr": "latest",
"@supabase/supabase-js": "latest",
"autoprefixer": "10.4.17",
"geist": "^1.2.1",
"next": "latest",
"postcss": "8.4.33",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.4.1",
"typescript": "5.3.3"
},
"devDependencies": {
"@types/node": "20.11.5",
"@types/react": "18.2.48",
"@types/react-dom": "18.2.18",
"encoding": "^0.1.13"
}
}

6
postcss.config.js Normal file
View File

@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};

20
tailwind.config.js Normal file
View File

@ -0,0 +1,20 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
colors: {
background: "hsl(var(--background))",
foreground: "hsl(var(--foreground))",
btn: {
background: "hsl(var(--btn-background))",
"background-hover": "hsl(var(--btn-background-hover))",
},
},
},
},
plugins: [],
};

28
tsconfig.json Normal file
View File

@ -0,0 +1,28 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}

7
utils/supabase/client.ts Normal file
View File

@ -0,0 +1,7 @@
import { createBrowserClient } from "@supabase/ssr";
export const createClient = () =>
createBrowserClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
);

View File

@ -0,0 +1,78 @@
import { createServerClient, type CookieOptions } from "@supabase/ssr";
import { type NextRequest, NextResponse } from "next/server";
export const updateSession = async (request: NextRequest) => {
// This `try/catch` block is only here for the interactive tutorial.
// Feel free to remove once you have Supabase connected.
try {
// Create an unmodified response
let response = NextResponse.next({
request: {
headers: request.headers,
},
});
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
get(name: string) {
return request.cookies.get(name)?.value;
},
set(name: string, value: string, options: CookieOptions) {
// If the cookie is updated, update the cookies for the request and response
request.cookies.set({
name,
value,
...options,
});
response = NextResponse.next({
request: {
headers: request.headers,
},
});
response.cookies.set({
name,
value,
...options,
});
},
remove(name: string, options: CookieOptions) {
// If the cookie is removed, update the cookies for the request and response
request.cookies.set({
name,
value: "",
...options,
});
response = NextResponse.next({
request: {
headers: request.headers,
},
});
response.cookies.set({
name,
value: "",
...options,
});
},
},
},
);
// This will refresh session if expired - required for Server Components
// https://supabase.com/docs/guides/auth/server-side/nextjs
await supabase.auth.getUser();
return response;
} catch (e) {
// If you are here, a Supabase client could not be created!
// This is likely because you have not set up environment variables.
// Check out http://localhost:3000 for Next Steps.
return NextResponse.next({
request: {
headers: request.headers,
},
});
}
};

36
utils/supabase/server.ts Normal file
View File

@ -0,0 +1,36 @@
import { createServerClient, type CookieOptions } from "@supabase/ssr";
import { cookies } from "next/headers";
export const createClient = () => {
const cookieStore = cookies();
return createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
get(name: string) {
return cookieStore.get(name)?.value;
},
set(name: string, value: string, options: CookieOptions) {
try {
cookieStore.set({ name, value, ...options });
} catch (error) {
// The `set` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
remove(name: string, options: CookieOptions) {
try {
cookieStore.set({ name, value: "", ...options });
} catch (error) {
// The `delete` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
},
},
);
};