-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.tsx
31 lines (25 loc) · 1008 Bytes
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// TODO: Duplicate or move this file outside the `_examples` folder to make it a route
import { createServerActionClient } from '@supabase/auth-helpers-nextjs'
import { revalidatePath } from 'next/cache'
import { cookies } from 'next/headers'
export const dynamic = 'force-dynamic'
export default async function ServerAction() {
const addTodo = async (formData: FormData) => {
'use server'
const title = formData.get('title')
if (title) {
// Create a Supabase client configured to use cookies
const supabase = createServerActionClient({ cookies })
// This assumes you have a `todos` table in Supabase. Check out
// the `Create Table and seed with data` section of the README 👇
// https://github.com/vercel/next.js/blob/canary/examples/with-supabase/README.md
await supabase.from('todos').insert({ title })
revalidatePath('/server-action-example')
}
}
return (
<form action={addTodo}>
<input name="title" />
</form>
)
}