Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
node_modules
dist
coverage/
.idea
4 changes: 4 additions & 0 deletions src/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('auth', () => {
accessToken: 'new-access-token',
organizationId: 'org_123456' as string | undefined,
role: 'admin' as string | undefined,
roles: ['admin'] as string[] | undefined,
permissions: ['read', 'write'] as string[] | undefined,
entitlements: ['premium'] as string[] | undefined,
featureFlags: ['flag-1', 'flag-2'] as string[] | undefined,
Expand Down Expand Up @@ -339,6 +340,7 @@ describe('auth', () => {
sessionId: 'session-123',
organizationId: 'org-456',
role: 'admin',
roles: ['admin'],
permissions: ['read', 'write'],
entitlements: ['feature-1', 'feature-2'],
featureFlags: ['flag-1', 'flag-2'],
Expand All @@ -361,6 +363,7 @@ describe('auth', () => {
sessionId: mockClaims.sessionId,
organizationId: mockClaims.organizationId,
role: mockClaims.role,
roles: mockClaims.roles,
permissions: mockClaims.permissions,
entitlements: mockClaims.entitlements,
featureFlags: mockClaims.featureFlags,
Expand Down Expand Up @@ -395,6 +398,7 @@ describe('auth', () => {
sessionId: 'session-123',
organizationId: 'org-456',
role: 'admin',
roles: ['admin'],
permissions: ['read', 'write'],
entitlements: ['feature-1', 'feature-2'],
featureFlags: ['flag-1', 'flag-2'],
Expand Down
2 changes: 2 additions & 0 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export async function withAuth(args: LoaderFunctionArgs): Promise<UserInfo | NoU
entitlements,
featureFlags,
role,
roles,
exp = 0,
} = getClaimsFromAccessToken(session.accessToken);

Expand All @@ -70,6 +71,7 @@ export async function withAuth(args: LoaderFunctionArgs): Promise<UserInfo | NoU
sessionId,
organizationId,
role,
roles,
permissions,
entitlements,
featureFlags,
Expand Down
5 changes: 5 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface AccessToken {
sid: string;
org_id?: string;
role?: string;
roles?: string[];
permissions?: string[];
entitlements?: string[];
feature_flags?: string[];
Expand All @@ -65,6 +66,7 @@ export interface UserInfo {
sessionId: string;
organizationId?: string;
role?: string;
roles?: string[];
permissions?: string[];
entitlements?: string[];
featureFlags?: string[];
Expand All @@ -77,6 +79,7 @@ export interface NoUserInfo {
sessionId?: undefined;
organizationId?: undefined;
role?: undefined;
roles?: undefined;
permissions?: undefined;
entitlements?: undefined;
featureFlags?: undefined;
Expand Down Expand Up @@ -110,6 +113,7 @@ export interface AuthorizedData {
sessionId: string;
organizationId: string | null;
role: string | null;
roles: string[] | null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, broken record here, why not string[] like permissions, entitlements, and featureFlags?

Copy link
Contributor Author

@atainter atainter Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing - consistency with role. If you have a strong opinion about consistency with the other array fields, I can change it.

permissions: string[];
entitlements: string[];
featureFlags: string[];
Expand All @@ -121,6 +125,7 @@ export interface UnauthorizedData {
sessionId: null;
organizationId: null;
role: null;
roles: null;
permissions: null;
entitlements: null;
featureFlags: null;
Expand Down
8 changes: 8 additions & 0 deletions src/session.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ describe('session', () => {
entitlements: null,
featureFlags: null,
role: null,
roles: null,
sessionId: null,
});
});
Expand Down Expand Up @@ -359,6 +360,7 @@ describe('session', () => {
sid: 'test-session-id',
org_id: 'org-123',
role: 'admin',
roles: ['admin'],
permissions: ['read', 'write'],
entitlements: ['premium'],
feature_flags: ['flag-1', 'flag-2'],
Expand Down Expand Up @@ -411,6 +413,7 @@ describe('session', () => {
entitlements: ['premium'],
featureFlags: ['flag-1', 'flag-2'],
role: 'admin',
roles: ['admin'],
sessionId: 'test-session-id',
});
});
Expand Down Expand Up @@ -559,6 +562,7 @@ describe('session', () => {
sid: 'test-session-id',
org_id: 'org-123',
role: null,
roles: [],
permissions: [],
entitlements: [],
feature_flags: [],
Expand All @@ -569,6 +573,7 @@ describe('session', () => {
sid: 'new-session-id',
org_id: 'org-123',
role: 'user',
roles: ['user'],
permissions: ['read'],
entitlements: ['basic'],
feature_flags: ['flag-1'],
Expand All @@ -594,6 +599,7 @@ describe('session', () => {
sessionId: 'new-session-id',
organizationId: 'org-123',
role: 'user',
roles: ['user'],
permissions: ['read'],
entitlements: ['basic'],
featureFlags: ['flag-1'],
Expand Down Expand Up @@ -738,6 +744,7 @@ describe('session', () => {
sid: 'new-session-id',
org_id: 'org-123',
role: 'user',
roles: ['user'],
permissions: ['read'],
entitlements: ['basic'],
feature_flags: ['flag-1'],
Expand All @@ -763,6 +770,7 @@ describe('session', () => {
accessToken: 'new.valid.token',
organizationId: 'org-123',
role: 'user',
roles: ['user'],
permissions: ['read'],
entitlements: ['basic'],
featureFlags: ['flag-1'],
Expand Down
7 changes: 7 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export async function refreshSession(request: Request, { organizationId }: { org
sessionId,
organizationId: newOrgId,
role,
roles,
permissions,
entitlements,
featureFlags,
Expand All @@ -83,6 +84,7 @@ export async function refreshSession(request: Request, { organizationId }: { org
accessToken,
organizationId: newOrgId,
role,
roles,
permissions,
entitlements,
featureFlags,
Expand Down Expand Up @@ -332,6 +334,7 @@ export async function authkitLoader<Data = unknown>(
entitlements: null,
featureFlags: null,
role: null,
roles: null,
sessionId: null,
};

Expand All @@ -343,6 +346,7 @@ export async function authkitLoader<Data = unknown>(
sessionId,
organizationId = null,
role = null,
roles = null,
permissions = [],
entitlements = [],
featureFlags = [],
Expand All @@ -365,6 +369,7 @@ export async function authkitLoader<Data = unknown>(
sessionId,
organizationId,
role,
roles,
permissions,
entitlements,
featureFlags,
Expand Down Expand Up @@ -497,6 +502,7 @@ export function getClaimsFromAccessToken(accessToken: string) {
sid: sessionId,
org_id: organizationId,
role,
roles,
permissions,
entitlements,
feature_flags: featureFlags,
Expand All @@ -510,6 +516,7 @@ export function getClaimsFromAccessToken(accessToken: string) {
sessionId,
organizationId,
role,
roles,
permissions,
entitlements,
featureFlags,
Expand Down