62 lines
3.0 KiB
Markdown
62 lines
3.0 KiB
Markdown
# nextjs-scribase-starter
|
|
|
|
Next.js 14 App Router starter wired to [Scribase](https://scribase.com): email/password
|
|
auth, a per-user Postgres table, and a welcome email on signup — the three things most
|
|
apps need from a backend, in one project, one account.
|
|
|
|
Agents: this works with zero human signup. `npx scribase init` with no prior login mints a
|
|
free 72-hour temporary project and writes real keys to `.env` — no form, no password, no
|
|
email confirmation. A human can claim the same project later from the printed link.
|
|
|
|
## Run it
|
|
|
|
```bash
|
|
git clone https://rithub.dev/scribase/nextjs-scribase-starter.git
|
|
cd nextjs-scribase-starter
|
|
npm install
|
|
npx scribase init --temp # or drop --temp once signed in (`npx scribase login`) for a real account
|
|
npx scribase sql "create table notes (id bigint generated always as identity primary key, user_id uuid not null references auth.users(id), body text not null, inserted_at timestamptz not null default now()); alter table notes enable row level security; create policy notes_owner on notes for all using (auth.uid() = user_id) with check (auth.uid() = user_id); grant select, insert, update, delete on notes to authenticated;"
|
|
npm run dev
|
|
```
|
|
|
|
Open `http://localhost:3000`, sign up with any email, and add a note. That's auth + a
|
|
real Postgres table with row-level security, no manual dashboard clicks.
|
|
|
|
## Email
|
|
|
|
Signup also sends a welcome email through [Scribase Mail](https://mail.scribase.com),
|
|
the Resend-shaped email API also behind this one account. It's optional: without
|
|
`SCRIBASE_MAIL_API_KEY` set in `.env`, the app logs why it skipped and keeps working.
|
|
Get a free `sk_test_...` key at mail.scribase.com — test keys simulate sends with no
|
|
domain verification and aren't metered, so you can try this without buying a domain.
|
|
|
|
```bash
|
|
echo 'SCRIBASE_MAIL_API_KEY=sk_test_...' >> .env
|
|
```
|
|
|
|
## What `scribase init` actually wrote to `.env`
|
|
|
|
```
|
|
SUPABASE_URL=... # this project's REST/auth endpoint (Scribase speaks the Supabase API)
|
|
SUPABASE_ANON_KEY=... # public key, safe in server code reading auth.uid()-scoped rows
|
|
```
|
|
|
|
Those two names are what `@supabase/ssr` and `@supabase/supabase-js` expect — this
|
|
template is a drop-in replacement for the official Supabase Next.js starter, pointed at
|
|
`api.<project>.scribase.com` instead of `*.supabase.co`.
|
|
|
|
## Deploy
|
|
|
|
Works on Vercel, Cloudflare, or any Node host. If the folder is linked to a Vercel
|
|
project (`vercel link`), re-running `npx scribase init` also copies the env vars onto
|
|
that Vercel project for you (`--no-vercel` to skip).
|
|
|
|
## Files
|
|
|
|
- `app/page.tsx` + `app/auth-form.tsx` — sign up / sign in forms (Server Actions)
|
|
- `app/notes/page.tsx` + `app/notes/note-form.tsx` — the protected, per-user notes list
|
|
- `app/actions.ts` — `signUp`, `signIn`, `signOut`, `addNote` Server Actions
|
|
- `lib/supabase-server.ts` — server-side Supabase/Scribase client
|
|
- `lib/mail.ts` — the welcome-email call to `mail-api.scribase.com`
|
|
- `middleware.ts` — refreshes the auth session cookie on every request
|