Skip to content

Commit d7e8015

Browse files
committed
Overlay branch overlay/session-ttl on top of origin/main via Merge
* apps/server/src/auth/SessionStore.test.ts * apps/server/src/auth/SessionStore.ts • 9a0ccc56d1 Overlay branch overlay/session-ttl on top of origin/main via Merge |\ | • d622731 Make the default session TTL configurable via T3CODE_SESSION_TTL • | 19108aa feat(auth): pairing grants access and T3 Connect management by default (pingdotgg#20432) • | 6a326af perf(web): connections settings compile with the React Compiler (pingdotgg#20515) • | 3448e01 perf(web): SnapShot settings compile with the React Compiler (pingdotgg#20514) • | 5422872 fix(web): an abandoned machine switch still clears its busy state (pingdotgg#20519) • | 6a71716 perf(web): theme import dialog compile with the React Compiler (pingdotgg#20513) • | 993aed3 perf(web): integrations settings compile with the React Compiler (pingdotgg#20512)
2 parents 19108aa + d622731 commit d7e8015

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎apps/server/src/auth/SessionStore.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,4 +850,18 @@ it.layer(NodeServices.layer)("SessionStore.layer", (it) => {
850850
expect((yield* readRow)[0]).toEqual({ surface: "mobile", appVersion: "1.3.0" });
851851
}).pipe(Effect.provide(Layer.mergeAll(layerSessionStore(), SqlitePersistence.layerMemory))),
852852
);
853+
it.effect("extends the default session TTL from T3CODE_SESSION_TTL", () =>
854+
Effect.gen(function* () {
855+
const sessions = yield* SessionStore.SessionStore;
856+
const before = process.env.T3CODE_SESSION_TTL;
857+
process.env.T3CODE_SESSION_TTL = "90";
858+
try {
859+
const issued = yield* sessions.issue({ subject: "env-ttl-probe" });
860+
expect(issued.expiresAt.epochMilliseconds).toBe(Duration.toMillis(Duration.days(90)));
861+
} finally {
862+
if (before === undefined) delete process.env.T3CODE_SESSION_TTL;
863+
else process.env.T3CODE_SESSION_TTL = before;
864+
}
865+
}).pipe(Effect.provide(makeSessionStoreLayer())),
866+
);
853867
});

‎apps/server/src/auth/SessionStore.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,16 @@ export class SessionStore extends Context.Service<
423423

424424
const SIGNING_SECRET_NAME = "server-signing-key";
425425
const DEFAULT_SESSION_TTL = Duration.days(30);
426+
427+
/** Default session lifetime in days; overrides the 30-day default when a
428+
* positive finite number, so long-lived or headless deployments can extend
429+
* paired sessions without re-pairing every month. */
430+
function defaultSessionTtl(): Duration.Duration {
431+
const raw = process.env.T3CODE_SESSION_TTL;
432+
if (!raw) return DEFAULT_SESSION_TTL;
433+
const days = Number(raw);
434+
return Number.isFinite(days) && days > 0 ? Duration.days(days) : DEFAULT_SESSION_TTL;
435+
}
426436
const DEFAULT_WEBSOCKET_TOKEN_TTL = Duration.minutes(5);
427437

428438
const SessionClaims = Schema.Struct({
@@ -658,7 +668,7 @@ export const make = Effect.gen(function* () {
658668
);
659669
const issuedAt = yield* DateTime.now;
660670
const expiresAt = DateTime.add(issuedAt, {
661-
milliseconds: Duration.toMillis(input?.ttl ?? DEFAULT_SESSION_TTL),
671+
milliseconds: Duration.toMillis(input?.ttl ?? defaultSessionTtl()),
662672
});
663673
const claims: SessionClaims = {
664674
v: 1,

0 commit comments

Comments
 (0)