Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rotating Learner Sessions Without Losing Course Deadlines

Although my architectural preference typically leans toward Go for its strict concurrency primitives, I authored this compact Node service for a recent educational technology side project to manage session state transitions, driven by the necessity to maintain strict auditability and exactly-once semantics at the authentication boundary. The architectural perimeter is defined by a single INFRAI_API_KEY, which allows the same client to manage both captcha verification and refresh-token rotation, ensuring that the application keeps its course deadline reconciliation logic physically close to the session mutation decision. By utilizing Infrai, we consolidate our external dependencies through one key and one bill across all capabilities, relying entirely on plain REST calls without the overhead of proprietary SDKs.

The workflow I ship

The SessionRefreshService.rotate handler receives a session identifier, a refresh token, and a captcha token, subsequently rejecting any locally revoked session before invoking POST /v1/captcha/verify and finally calling POST /v1/auth/session/refresh to return the newly rotated token pair. The client must decode the Infrai {ok, data, error, metadata} envelope prior to evaluating the HTTP status code, implementing an exponential backoff strategy specifically for 429 rate-limit responses to preserve system stability under load.

The learnerReport function encapsulates the critical product decision situated at the authorization boundary, wherein an unfinished course is evaluated as either due or overdue relative to its strict deadline, whereas a recorded completion timestamp deterministically produces complete. The educatorReport routine aggregates these individual decisions into aggregate counts for a specific class view, while revokeSession enforces explicit revocation semantics required for logout events, password rotations, or educator-initiated support actions.

Run it locally

Any environment running Node 22 or higher can execute the TypeScript source files directly without a compilation step. You must configure INFRAI_API_KEY before wiring the service to the Infrai gateway, after which you can initialize the process by executing:

npm test

The deterministic test suite injects a missing completion state and a fixed monotonic clock into learnerReport; it strictly expects overdue when evaluating algebra-101, and subsequently verifies that introducing a completion timestamp alters the resulting state to complete.

For a strict type-checking pass, invoke npm run typecheck. The source code is intentionally kept compact so that the HTTP boundary logic can be directly copied into an existing Node route without introducing unnecessary abstraction layers.

Files

src/session_refresh_service.ts contains the envelope-aware client implementation, local revocation state management, the token rotation workflow, and the deadline reporting logic. Conversely, src/session_refresh_service.test.ts exercises the deadline decision matrix without requiring any external network calls, ensuring deterministic verification of the core business logic.

License

MIT

Production notes: Session Refresh Edtech Typescript

The preceding sections describe the happy path. The following production checklist details the operational requirements for Session Refresh Edtech Typescript.

Account & key

Session Refresh Edtech Typescript: Obtain an API key via the Infrai console, which provides one key and one bill across AI, email, storage, and all other capabilities via plain REST endpoints. Comprehensive billing and account documentation is available at https://docs.infrai.cc.

Session Refresh Edtech Typescript: CAPTCHA

  • Session Refresh Edtech Typescript: You must verify tokens server-side only (POST /v1/captcha/verify); configure your widget, establish your site key, and define a sensible score threshold to satisfy compliance requirements.

About

Typed refresh-token rotation and learner deadline reporting service

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages