Skip to content

Commit 4e7998b

Browse files
committed
fix: custom events sql
1 parent ccf0ed7 commit 4e7998b

File tree

10 files changed

+629
-119
lines changed

10 files changed

+629
-119
lines changed

apps/api/src/lib/api-key.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,16 @@ export function isApiKeyPresent(headers: Headers): boolean {
108108
}
109109

110110
export async function resolveEffectiveScopesForWebsite(
111-
key: ApiKeyRow,
111+
key: ApiKeyRow | null,
112112
websiteId: string
113113
): Promise<Set<ApiScope>> {
114+
if (!key) {
115+
logger.debug('Cannot resolve scopes for null API key', { websiteId });
116+
return new Set();
117+
}
118+
114119
const effective = new Set<ApiScope>();
115-
for (const s of key.scopes) {
120+
for (const s of key.scopes || []) {
116121
effective.add(s as ApiScope);
117122
}
118123

@@ -133,18 +138,26 @@ export async function resolveEffectiveScopesForWebsite(
133138
apikeyId: key.id,
134139
websiteId,
135140
effectiveScopes: Array.from(effective),
136-
globalScopes: key.scopes,
141+
globalScopes: key.scopes || [],
137142
accessEntriesCount: entries.length,
138143
});
139144

140145
return effective;
141146
}
142147

143148
export async function hasWebsiteScope(
144-
key: ApiKeyRow,
149+
key: ApiKeyRow | null,
145150
websiteId: string,
146151
required: ApiScope
147152
): Promise<boolean> {
153+
if (!key) {
154+
logger.debug('Scope check failed: null API key', {
155+
websiteId,
156+
requiredScope: required,
157+
});
158+
return false;
159+
}
160+
148161
if ((key.scopes || []).includes(required)) {
149162
logger.debug('Scope check passed via global scope', {
150163
apikeyId: key.id,

0 commit comments

Comments
 (0)