Better-auth endpoints
All authentication endpoints are mounted at/api/auth/* on the server:
Session handling
Sessions are stored in cookies and automatically included in all requests when usingcredentials: "include":
Session context
Every oRPC procedure receives the session in its context:Protected procedures
Most API endpoints useprotectedProcedure, which requires an authenticated session:
UNAUTHORIZED error:
Admin procedures
Some endpoints require admin role usingadminProcedure:
UNAUTHORIZED- No session foundFORBIDDEN- User is not an admin
Example: Login flow
Example: Protected route
Organizations
Nanahoshi supports multi-tenancy via better-auth’s organizations plugin. Each library and its books are scoped to an organization. The active organization is stored insession.session.activeOrganizationId and used to filter queries: