@binary1702/auth 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PROMPT.md +80 -0
- package/README.md +2 -0
- package/package.json +3 -2
package/PROMPT.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Agent prompt: install @binary1702/auth
|
|
2
|
+
|
|
3
|
+
Copy everything below the line into an AI coding agent running inside the Next.js project.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Install `@binary1702/auth` in this project. It adds username + password auth to a Next.js App Router app. Follow these steps exactly and report the result of each.
|
|
8
|
+
|
|
9
|
+
## Before you start
|
|
10
|
+
|
|
11
|
+
Check these and stop if any fails:
|
|
12
|
+
|
|
13
|
+
- `app/` or `src/app/` exists (App Router). Pages Router is not supported.
|
|
14
|
+
- A Postgres connection string is available. Look for `DATABASE_URL` or `NEON_DATABASE_URL` in `.env.local` or the environment. If none exists, ask me for one.
|
|
15
|
+
- If the project already has auth (a `proxy.ts` or `middleware.ts` that checks sessions, or packages like next-auth, better-auth, clerk, `@neondatabase/auth`), tell me before continuing. This package will put its own sign-in in front of everything.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
Run, in the project root:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx @binary1702/auth
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
It is interactive. It asks for the Postgres connection string, then a username and a password for the first user. If you cannot answer prompts, run it and hand control to me.
|
|
26
|
+
|
|
27
|
+
It does the following, skipping anything already done:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
✓ @binary1702/auth installed → package.json
|
|
31
|
+
✓ DATABASE_URL → .env.local
|
|
32
|
+
✓ AUTH_SECRET generated → .env.local
|
|
33
|
+
✓ app/auth/[...path]/route.ts → export { GET, POST } from "@binary1702/auth/next"
|
|
34
|
+
✓ proxy.ts → guard in front of every route
|
|
35
|
+
✓ auth_users table ready → in the database
|
|
36
|
+
✓ user "<name>" created
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
If `proxy.ts` or `middleware.ts` already existed, the CLI does not touch it and prints a snippet instead. Merge the snippet into the existing file: call the package's `proxy` for the paths you want protected and keep the matcher inline. On Next 15 the file is `middleware.ts`, same content.
|
|
40
|
+
|
|
41
|
+
## Verify
|
|
42
|
+
|
|
43
|
+
Start the dev server and check with real HTTP requests:
|
|
44
|
+
|
|
45
|
+
| Request | Expect |
|
|
46
|
+
|---|---|
|
|
47
|
+
| `GET /` with no cookie | redirect to `/auth/sign-in` |
|
|
48
|
+
| `GET /auth/sign-in` | 200, HTML form |
|
|
49
|
+
| `GET /api/<any>` with no cookie | 401 JSON |
|
|
50
|
+
| `POST /auth/sign-in` JSON `{ "username", "password" }` | 200 `{ user }` and `Set-Cookie: auth_session=…; HttpOnly` |
|
|
51
|
+
| `GET /auth/session` with that cookie | `{ user: { id, username } }` |
|
|
52
|
+
| `GET /auth/sign-out` | cookie cleared, redirect to sign-in |
|
|
53
|
+
|
|
54
|
+
Then open `/auth/sign-in` in the browser, sign in, confirm you land on `/`.
|
|
55
|
+
|
|
56
|
+
## Wire it into the code
|
|
57
|
+
|
|
58
|
+
Wherever the app needs the current user on the server:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { requireUser } from "@binary1702/auth/next"
|
|
62
|
+
|
|
63
|
+
const user = await requireUser() // { id, username } or throws AuthError (401)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`getUser()` returns `null` instead of throwing. Both work in route handlers, server components and server actions.
|
|
67
|
+
|
|
68
|
+
For sign-out, link to `/auth/sign-out`. For client code, `fetch("/auth/session")`.
|
|
69
|
+
|
|
70
|
+
Do not build a sign-up page. Users are created with `npx @binary1702/auth add-user`.
|
|
71
|
+
|
|
72
|
+
## Deploy
|
|
73
|
+
|
|
74
|
+
Copy `DATABASE_URL` and `AUTH_SECRET` from `.env.local` into the host's environment. Nothing else.
|
|
75
|
+
|
|
76
|
+
## Report
|
|
77
|
+
|
|
78
|
+
Tell me, in order: each install step and whether it was done or skipped, each verify row with the actual status code, anything that failed with the error text verbatim, and anything that took more steps than it should. Do not modify the package itself, only this project.
|
|
79
|
+
|
|
80
|
+
Docs: https://www.npmjs.com/package/@binary1702/auth
|
package/README.md
CHANGED
|
@@ -8,6 +8,8 @@ npx @binary1702/auth
|
|
|
8
8
|
|
|
9
9
|
One command. It installs itself, writes two env vars, writes two files, creates the table, creates your first user. Then you move on.
|
|
10
10
|
|
|
11
|
+
Letting an AI agent do the install? Paste [PROMPT.md](./PROMPT.md) into it. Same steps, written for an agent, with the checks to run and what to report back. [INSTALL.md](./INSTALL.md) is the short human version.
|
|
12
|
+
|
|
11
13
|
---
|
|
12
14
|
|
|
13
15
|
## Quick start (new project)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@binary1702/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Username + password auth for Next.js. One command: npx @binary1702/auth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"dist",
|
|
33
|
-
"INSTALL.md"
|
|
33
|
+
"INSTALL.md",
|
|
34
|
+
"PROMPT.md"
|
|
34
35
|
],
|
|
35
36
|
"scripts": {
|
|
36
37
|
"build": "tsc",
|