Skip to content

Commit

Permalink
Merge branch 'canary' into shu/5b18
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding authored Oct 24, 2023
2 parents b2ecf43 + ce085b5 commit 656c590
Show file tree
Hide file tree
Showing 45 changed files with 814 additions and 435 deletions.
48 changes: 13 additions & 35 deletions examples/with-supabase/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
<a href="https://demo-nextjs-with-supabase.vercel.app/">
<img alt="Next.js 13 and app template Router-ready Supabase starter kit." src="https://demo-nextjs-with-supabase.vercel.app/opengraph-image.png">
<h1 align="center">Supabase starter kit</h1>
<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">
This starter configures Supabase Auth to use cookies, making the user's session available throughout the entire Next.js app - Client Components, Server Components, Route Handlers, Server Actions and Middleware.
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="#how-to-use"><strong>How to use</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

- [Next.js App router ready](https://nextjs.org) App Router
- Client Components examples
- React Server Components (RSCs) examples
- Route Handlers examples
- Server Actions examples
- [supabase-js](https://supabase.com/docs/reference/javascript). Supabase's
isomorphic JavaScript library.
- [Supabase Auth](https://supabase.com/auth) using cookies, making the user's session available throughout the entire Next.js app, for both client and server.
- 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
Expand All @@ -45,7 +45,7 @@ After installation of the Supabase integration, all relevant environment variabl

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](#how-to-use).
If you wish to just develop locally and not deploy to Vercel, [follow the steps below](#clone-and-run-locally).

## Clone and run locally

Expand Down Expand Up @@ -82,27 +82,6 @@ If you wish to just develop locally and not deploy to Vercel, [follow the steps

> Check out [the docs for Local Development](https://supabase.com/docs/guides/getting-started/local-development) to also run Supabase locally.

## How to use

There are a variety of example files for you to copy and build your app with in the starter kit.

### Create a Supabase client

Check out the [`/app/_examples`](./app/_examples/) folder for an example of creating a Supabase client in:

- [Client Components](./app/_examples/client-component/page.tsx)
- [Server Components](./app/_examples/server-component/page.tsx)
- [Route Handlers](./app/_examples/route-handler/route.ts)
- [Server Actions](./app/_examples/server-action/page.tsx)

### Create `todo` table and seed with data (optional)

Navigate to [your project's SQL Editor](https://app.supabase.com/project/_/sql), click `New query`, paste the contents of the [init.sql](./supabase/migrations/20230618024722_init.sql) file and click `RUN`.
This will create a basic `todos` table, enable Row Level Security (RLS), and write RLS policies enabling `select` and `insert` actions for `authenticated` users.
To seed your `todos` table with some dummy data, run the contents of the [seed.sql](./supabase/seed.sql) file.
## Feedback and issues

Please file feedback and issues over on the [Supabase GitHub org](https://github.com/supabase/supabase/issues/new/choose).
Expand All @@ -112,4 +91,3 @@ Please file feedback and issues over on the [Supabase GitHub org](https://github
- [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)
- [Next.js Auth Helpers Docs](https://supabase.com/docs/guides/auth/auth-helpers/nextjs)
29 changes: 0 additions & 29 deletions examples/with-supabase/app/_examples/client-component/page.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions examples/with-supabase/app/_examples/route-handler/route.ts

This file was deleted.

31 changes: 0 additions & 31 deletions examples/with-supabase/app/_examples/server-action/page.tsx

This file was deleted.

18 changes: 0 additions & 18 deletions examples/with-supabase/app/_examples/server-component/page.tsx

This file was deleted.

5 changes: 2 additions & 3 deletions examples/with-supabase/app/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers'
import { createClient } from '@/utils/supabase/server'
import { NextResponse } from 'next/server'

export const dynamic = 'force-dynamic'
Expand All @@ -12,7 +11,7 @@ export async function GET(request: Request) {
const code = requestUrl.searchParams.get('code')

if (code) {
const supabase = createRouteHandlerClient({ cookies })
const supabase = createClient()
await supabase.auth.exchangeCodeForSession(code)
}

Expand Down
5 changes: 2 additions & 3 deletions examples/with-supabase/app/auth/sign-in/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers'
import { createClient } from '@/utils/supabase/server'
import { NextResponse } from 'next/server'

export const dynamic = 'force-dynamic'
Expand All @@ -9,7 +8,7 @@ export async function POST(request: Request) {
const formData = await request.formData()
const email = String(formData.get('email'))
const password = String(formData.get('password'))
const supabase = createRouteHandlerClient({ cookies })
const supabase = createClient()

const { error } = await supabase.auth.signInWithPassword({
email,
Expand Down
5 changes: 2 additions & 3 deletions examples/with-supabase/app/auth/sign-out/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers'
import { createClient } from '@/utils/supabase/server'
import { NextResponse } from 'next/server'

export const dynamic = 'force-dynamic'

export async function POST(request: Request) {
const requestUrl = new URL(request.url)
const supabase = createRouteHandlerClient({ cookies })
const supabase = createClient()

await supabase.auth.signOut()

Expand Down
5 changes: 2 additions & 3 deletions examples/with-supabase/app/auth/sign-up/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers'
import { createClient } from '@/utils/supabase/server'
import { NextResponse } from 'next/server'

export const dynamic = 'force-dynamic'
Expand All @@ -9,7 +8,7 @@ export async function POST(request: Request) {
const formData = await request.formData()
const email = String(formData.get('email'))
const password = String(formData.get('password'))
const supabase = createRouteHandlerClient({ cookies })
const supabase = createClient()

const { error } = await supabase.auth.signUp({
email,
Expand Down
8 changes: 4 additions & 4 deletions examples/with-supabase/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import './globals.css'

export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
title: 'Next.js and Supabase Starter Kit',
description: 'The fastest way to build apps with Next.js and Supabase',
}

export default function RootLayout({
Expand All @@ -12,8 +12,8 @@ export default function RootLayout({
}) {
return (
<html lang="en">
<body>
<main className="min-h-screen bg-background flex flex-col items-center">
<body className="bg-background text-foreground">
<main className="min-h-screen flex flex-col items-center">
{children}
</main>
</body>
Expand Down
4 changes: 2 additions & 2 deletions examples/with-supabase/app/login/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export default function Messages() {
return (
<>
{error && (
<p className="mt-4 p-4 bg-neutral-900 text-neutral-300 text-center">
<p className="mt-4 p-4 bg-foreground/10 text-foreground text-center">
{error}
</p>
)}
{message && (
<p className="mt-4 p-4 bg-neutral-900 text-neutral-300 text-center">
<p className="mt-4 p-4 bg-foreground/10 text-foreground text-center">
{message}
</p>
)}
Expand Down
4 changes: 2 additions & 2 deletions examples/with-supabase/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ export default function Login() {
placeholder="••••••••"
required
/>
<button className="bg-green-700 rounded px-4 py-2 text-white mb-2">
<button className="bg-green-700 rounded-md px-4 py-2 text-foreground mb-2">
Sign In
</button>
<button
formAction="/auth/sign-up"
className="border border-gray-700 rounded px-4 py-2 text-black mb-2"
className="border border-foreground/20 rounded-md px-4 py-2 text-foreground mb-2"
>
Sign Up
</button>
Expand Down
Loading

0 comments on commit 656c590

Please sign in to comment.