Skip to content

feat(cli): authenticated coupon + bounty submission from the CLI#33

Merged
ralyodio merged 1 commit into
masterfrom
feat/cli-auth-submit
Jun 17, 2026
Merged

feat(cli): authenticated coupon + bounty submission from the CLI#33
ralyodio merged 1 commit into
masterfrom
feat/cli-auth-submit

Conversation

@ralyodio

Copy link
Copy Markdown
Contributor

Adds CLI support for adding coupons and bounties, with a CoinPay-OAuth login (login URL → paste code, like gh/Claude device login).

Auth mechanism

The session is already an HMAC-signed token (createSession). This PR:

  • getSessionDid() also accepts it via Authorization: Bearer <token> (browser still uses the httpOnly cookie).
  • New /cli-auth page: after CoinPay OAuth it displays your token to paste into the CLI (noindex); otherwise shows "Connect with CoinPay".

CLI (apps/web/public/cli/c0upons, v1.0.0 → v1.1.0)

  • c0upons login — prints WEB/cli-auth, reads the pasted token, verifies it via /api/auth/me, saves to $XDG_CONFIG_HOME/c0upons/token (chmod 600).
  • c0upons logout — forgets the token.
  • c0upons submit — post a coupon: --title --store --code --percent|--off --url --description --expiry.
  • c0upons bounty — post a bounty: --title --store --reward --url --description; prints the bounty URL + CoinPay funding link.
  • Payloads built with jq -n (safe escaping); 401 → "run c0upons login".

Example:

c0upons login
c0upons submit --store Nike --title '20% off' --code SAVE20 --percent 20 --url https://nike.com
c0upons bounty --store Adidas --title 'Need a 30% off code' --reward 1.00

Verification

  • bash -n clean; web tsc + next build green (/cli-auth route builds).
  • Ran a local prod server against the real DB: Bearer auth returns the DID (200) and 401 without; /cli-auth renders; real coupon + bounty inserts via Bearer succeeded (status 201) — test rows deleted afterward.

Note: requires this to be deployed before the live CLI's new commands work (the Bearer acceptance is server-side).

🤖 Generated with Claude Code

Adds a device-style login (login URL + paste code) and write commands to
the shipped bash CLI, plus the backend support for token auth.

Backend:
- getSessionDid() now also accepts the signed session token via
  `Authorization: Bearer <token>` (browser still uses the httpOnly
  cookie). This lets the CLI authenticate as the user.
- New /cli-auth page: after CoinPay OAuth it shows the user's token to
  copy-paste into the CLI; otherwise it offers "Connect with CoinPay".
  noindex.

CLI (apps/web/public/cli/c0upons, v1.0.0 → v1.1.0):
- `login`   — prints WEB/cli-auth, reads pasted token, verifies via
  /api/auth/me, saves to $XDG_CONFIG_HOME/c0upons/token (chmod 600).
- `logout`  — forgets the token.
- `submit`  — post a coupon (--title/--store/--code/--percent|--off/
  --url/--description/--expiry).
- `bounty`  — post a bounty (--title/--store/--reward/--url/--desc);
  prints the bounty URL + CoinPay funding link.
- Payloads built with `jq -n` for safe escaping; authed POSTs send the
  bearer token; clear 401 handling ("run c0upons login").

Verified: bearer auth (200 with token / 401 without), /cli-auth render,
and real coupon+bounty inserts via bearer (test rows cleaned up).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

vu1nz Security Review

0 finding(s) in PR #?

No security issues found.

@ralyodio ralyodio merged commit 428ba16 into master Jun 17, 2026
5 checks passed
@ralyodio ralyodio deleted the feat/cli-auth-submit branch June 17, 2026 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant