35 lines
900 B
TypeScript
35 lines
900 B
TypeScript
import { redirect } from "next/navigation";
|
|
import { supabaseServer } from "@/lib/supabase-server";
|
|
import { NoteForm } from "./note-form";
|
|
|
|
export default async function NotesPage() {
|
|
const supabase = supabaseServer();
|
|
const { data: userData } = await supabase.auth.getUser();
|
|
if (!userData.user) {
|
|
redirect("/");
|
|
}
|
|
|
|
const { data: notes, error } = await supabase
|
|
.from("notes")
|
|
.select("id, body, inserted_at")
|
|
.order("inserted_at", { ascending: false });
|
|
|
|
return (
|
|
<main>
|
|
<h1>Your notes</h1>
|
|
<p>Signed in as {userData.user.email}.</p>
|
|
<NoteForm />
|
|
{error && (
|
|
<p style={{ color: "crimson" }}>
|
|
{error.message} — did you run the `notes` table SQL from the README?
|
|
</p>
|
|
)}
|
|
<ul>
|
|
{(notes ?? []).map((note) => (
|
|
<li key={note.id}>{note.body}</li>
|
|
))}
|
|
</ul>
|
|
</main>
|
|
);
|
|
}
|