@owlmeans/auth
v0.1.7
Published
Core authentication types, schemas, and constants for OwlMeans fullstack applications.
Readme
@owlmeans/auth
Core authentication types, schemas, and constants for OwlMeans fullstack applications.
Overview
- Defines the shared
Auth,AuthCredentials,AuthPayload, andAuthTokentypes used by all auth-related packages - Provides AJV schemas for validating auth requests (
AuthCredentialsSchema,AllowanceRequestSchema, etc.) - Defines the
AuthRoleandAuthenticationStageenums used across server and client - Used in request handlers to access
req.authand throw typed auth errors
Installation
bun add @owlmeans/authUsage
Throw a typed auth error when a request lacks an entity:
import { AuthUnknown } from '@owlmeans/auth'
export const create = handleBody(async (body, context, request) => {
if (request.auth?.entityId == null) {
throw new AuthUnknown('entity')
}
// ...
})Check authentication stage in a WebSocket connection:
import { AuthenticationStage } from '@owlmeans/auth'
if (connection.stage !== AuthenticationStage.Authenticated) {
throw new AuthUnknown('not-authenticated')
}API
Types
Auth— the auth object attached torequest.auth; containsuserId,entityId,role,scopesAuthCredentials— signed credential payload withchallenge,credential,publicKeyAuthPayload— base payload withtype,role,userId,profileId,expiresAtAuthToken— JWT-like token structure
Enums
enum AuthRole { User, Guest, Service, System, Admin, Superuser, Blocked }
enum AuthenticationType { BasicEd25519, OneTimeToken, ReCaptcha }
enum AuthenticationStage { /* connection auth lifecycle */ }Errors
AuthUnknown— thrown when a request is missing or has invalid auth
Product-Viable Integration Notes
- Manager API handlers use
AuthUnknown('entity')whenrequest.auth?.entityIdis missing. - WebSocket helpers use
Auth,AuthToken, andAuthenticationStageto authenticate token-bearing connections. - Google/OIDC login is normalized into an
AuthPayloadwithuserId,profileId,entityId, andscopes; the local identity store lives in@owlmeans/server-auth-identity. - Gate denial should use
AuthForbidden; product ownership checks should stay in module gates or handlers, not in this core package.
AJV Schemas (for module filter definitions)
AuthCredentialsSchema— validates an auth credential request bodyAllowanceRequestSchema— validates an allowance/init request bodyAuthTokenSchema— validates query params containing an auth token
Related Packages
@owlmeans/auth-common— auth modules, guards, and middleware@owlmeans/server-auth— server-side auth service implementation@owlmeans/client-auth— client-side auth service
