Skip to content

Commit 434ca8f

Browse files
committed
Show friendly labels for capped duration values
1 parent 83e779d commit 434ca8f

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

apps/webapp/app/services/sessionDuration.server.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { commitSession } from "./sessionStorage.server";
55

66
export const SESSION_ISSUED_AT_KEY = "session:issuedAt";
77

8-
export const DEFAULT_SESSION_DURATION_SECONDS = 60 * 60 * 24 * 365;
8+
// Months and years use standard Gregorian-calendar conversions (365.2425 days/yr,
9+
// 30.436875 days/month) so values produced by external "X months in seconds"
10+
// calculators map cleanly to a labeled option.
11+
const GREGORIAN_YEAR_SECONDS = 31_556_952; // 365.2425 * 86400
12+
const GREGORIAN_HALF_YEAR_SECONDS = 15_778_476;
13+
14+
export const DEFAULT_SESSION_DURATION_SECONDS = GREGORIAN_YEAR_SECONDS;
915

1016
export type SessionDurationOption = {
1117
value: number;
@@ -18,8 +24,8 @@ export const SESSION_DURATION_OPTIONS: SessionDurationOption[] = [
1824
{ value: 60 * 60, label: "1 hour" },
1925
{ value: 60 * 60 * 24, label: "1 day" },
2026
{ value: 60 * 60 * 24 * 30, label: "30 days" },
21-
{ value: 60 * 60 * 24 * 30 * 6, label: "6 months" },
22-
{ value: 60 * 60 * 24 * 365, label: "1 year" },
27+
{ value: GREGORIAN_HALF_YEAR_SECONDS, label: "6 months" },
28+
{ value: GREGORIAN_YEAR_SECONDS, label: "1 year" },
2329
];
2430

2531
export const ALLOWED_SESSION_DURATION_VALUES: ReadonlySet<number> = new Set(

apps/webapp/test/sessionDuration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818

1919
const oneHour = 60 * 60;
2020
const oneDay = 60 * 60 * 24;
21-
const oneYear = 60 * 60 * 24 * 365;
21+
const oneYear = DEFAULT_SESSION_DURATION_SECONDS;
2222

2323
const sessionStorage = createCookieSessionStorage({
2424
cookie: { name: "__test_session", secrets: ["test"] },
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "public"."User" ALTER COLUMN "sessionDuration" SET DEFAULT 31556952;

internal-packages/database/prisma/schema.prisma

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ model User {
5454
/// Hash of the last used code to prevent replay attacks
5555
mfaLastUsedCode String?
5656
57-
/// Maximum session lifetime in seconds for this user. Default = 1 year.
57+
/// Maximum session lifetime in seconds for this user. Default = 1 year (Gregorian).
5858
/// May be further restricted by Organization.maxSessionDuration on any of the user's orgs.
59-
sessionDuration Int @default(31536000)
59+
sessionDuration Int @default(31556952)
6060
6161
invitationCode InvitationCode? @relation(fields: [invitationCodeId], references: [id])
6262
invitationCodeId String?

0 commit comments

Comments
 (0)