Skip to content

feat: expose jwt helpers for app starter kit - #9

Merged
coladarci merged 1 commit into
mainfrom
feature/expose-jwt-helpers
Jun 29, 2026
Merged

feat: expose jwt helpers for app starter kit#9
coladarci merged 1 commit into
mainfrom
feature/expose-jwt-helpers

Conversation

@coladarci

@coladarci coladarci commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

What

Adds verifyPeekAuthToken(token) to PeekAccessService and exports typed claim shapes so callers can verify Peek app registry JWTs without pulling in jsonwebtoken directly.

Why

The app starter kit needs to authenticate incoming requests from the Peek app registry. The token is an HMAC-signed JWT with a known shape (iss: "app_registry_v2", nested user object, display_version, etc.). Without this, each app would re-implement verify logic and define its own ad-hoc claim types.

Changes

  • src/models/auth-token.ts — new PeekAuthTokenClaims and PeekAuthTokenUser interfaces modeled on the actual registry token shape
  • PeekAccessService.verifyPeekAuthToken(token) — verifies signature (jwtSecret from config), expiry, and iss: "app_registry_v2"; returns typed claims; re-throws jsonwebtoken errors (JsonWebTokenError / TokenExpiredError / NotBeforeError) for callers to distinguish
  • src/index.ts — exports PeekAuthTokenClaims and PeekAuthTokenUser
  • 8 new tests: valid token (claims + user fields + isAdmin), wrong secret, wrong issuer, expired, malformed

Usage

import { PeekAccessService, type PeekAuthTokenClaims } from "@peektravel/app-utilities";

const peek = new PeekAccessService({ jwtSecret: process.env.PEEK_SECRET!, ... });

try {
  const claims: PeekAuthTokenClaims = peek.verifyPeekAuthToken(req.headers["x-peek-token"]);
  // claims.installId, claims.user.email, claims.user.isAdmin, ...
} catch (err) {
  // JsonWebTokenError, TokenExpiredError, NotBeforeError
}

@coladarci
coladarci force-pushed the feature/expose-jwt-helpers branch from 46dec8e to 4739e03 Compare June 29, 2026 23:54
@coladarci
coladarci merged commit aaf75d7 into main Jun 29, 2026
2 checks passed
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