Skip to content

Commit ba7c70d

Browse files
committed
fix(session-policy): unify join paths on applySessionPolicyToNewMember; final audit polish (dead exports, response bound, test name)
1 parent d1f43f0 commit ba7c70d

4 files changed

Lines changed: 10 additions & 12 deletions

File tree

apps/sim/ee/session-policy/components/session-policy-settings.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,3 @@ export function SessionPolicySettings({ organizationId }: SessionPolicySettingsP
213213
</>
214214
)
215215
}
216-
217-
export default SessionPolicySettings

apps/sim/lib/api/contracts/organization.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,10 @@ export const organizationSessionPolicyResponseSchema = z.object({
197197
export const revokeOrganizationSessionsResponseSchema = z.object({
198198
success: z.boolean(),
199199
data: z.object({
200-
revokedSessions: z.number().int(),
200+
revokedSessions: z.number().int().min(0),
201201
}),
202202
})
203203

204-
export type RevokeOrganizationSessionsResult = z.output<
205-
typeof revokeOrganizationSessionsResponseSchema
206-
>['data']
207-
208204
export const updateOrganizationWhitelabelBodySchema = z.object({
209205
brandName: z
210206
.string()

apps/sim/lib/auth/session-policy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('clampSessionExpiry', () => {
4747
expect(result.getTime()).toBe(now.getTime() + 48 * HOUR_MS)
4848
})
4949

50-
it('floors idleTimeoutHours at the cookie-cache window', () => {
50+
it('floors idleTimeoutHours at twice the cookie-cache window', () => {
5151
const result = clampSessionExpiry(policy({ idleTimeoutHours: 1 }), createdAt, proposed, now)
5252
expect(result.getTime()).toBe(now.getTime() + MIN_IDLE_TIMEOUT_HOURS * HOUR_MS)
5353
})

apps/sim/lib/billing/organizations/membership.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { generateId } from '@sim/utils/id'
2525
import { normalizeEmail } from '@sim/utils/string'
2626
import { and, count, eq, inArray, isNull, ne, or, sql } from 'drizzle-orm'
2727
import { invalidateMembershipCache } from '@/lib/auth/security-policy'
28+
import { applySessionPolicyToNewMember } from '@/lib/auth/session-policy'
2829
import { syncUsageLimitsFromSubscription } from '@/lib/billing/core/usage'
2930
import {
3031
assertNoUnresolvedEnterpriseIssuance,
@@ -632,7 +633,9 @@ export async function ensureUserInOrganization(
632633
const result = await addUserToOrganization(params)
633634

634635
if (result.success) {
635-
invalidateMembershipCache(params.userId)
636+
// Invalidates the membership cache and clamps pre-join sessions to the
637+
// org policy — same treatment as invite acceptance. Best-effort.
638+
await applySessionPolicyToNewMember(params.userId, params.organizationId)
636639
}
637640

638641
return {
@@ -1518,9 +1521,10 @@ export async function transferUserBetweenOrganizations(
15181521
}
15191522
}
15201523
)
1521-
// The transferred member's cookie-version/hook-clamp fallbacks must
1522-
// resolve to the destination org immediately, not after the cache TTL.
1523-
invalidateMembershipCache(params.userId)
1524+
// The transferred member's fallbacks must resolve to the destination org
1525+
// immediately, and their sessions clamp to its policy — same treatment as
1526+
// invite acceptance. Best-effort.
1527+
await applySessionPolicyToNewMember(params.userId, params.destinationOrganizationId)
15241528
return transferResult
15251529
} catch (error) {
15261530
logger.error('Failed to transfer organization member', { ...params, error })

0 commit comments

Comments
 (0)