Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

buddy-identity-example

Showcase of @buddy-works/identity — zero-config authentication for apps running behind Buddy tunnels. Next.js App Router, plain npm, the library installed from the npm registry.

What it demonstrates:

  • / — user card with the current user's data, rendered twice:
    • in a Server Component via getCurrentUser(await headers()),
    • in a Client Component via getCurrentUser() (browser, cookie attached automatically).
  • /admin — page gated server-side by user.admin.
  • /reports — page gated server-side by membership in the finance group (workspace admins also pass). Groups are managed centrally in Buddy.
  • /api/whoami — Route Handler using getCurrentUser(request).

Run locally

npm install
npm run dev          # http://localhost:3000

Locally there is no tunnel, so /.buddy/auth/me is mocked via a rewrite in next.config.mjs + app/api/mock/me/route.ts. Switch user states with MOCK:

MOCK=owner npm run dev        # workspace owner
MOCK=admin npm run dev        # workspace admin (default)
MOCK=member npm run dev       # regular member — blocked on /admin and /reports
MOCK=finance npm run dev      # member of the `finance` group — allowed on /reports
MOCK=logged-out npm run dev   # no session

Behind a real Buddy tunnel

Disable the mock and let the tunnel intercept /.buddy/auth/me:

MOCK=0 npm run build && MOCK=0 npm run start

Access is managed centrally in the tunnel settings — your code just receives trusted user information.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages