Skip to content

Commit

Permalink
fix: ensure workspace is loaded (unkeyed#2470)
Browse files Browse the repository at this point in the history
  • Loading branch information
chronark authored Oct 16, 2024
1 parent c55b5aa commit 8b37287
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion apps/api/src/pkg/keys/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,26 @@ export class KeyService {
this.logger.info("data from cache or db", {
data,
});
// Quick fix
if (!data.workspace) {
this.logger.warn("workspace not found, trying again", {
workspace: data.key.workspaceId,
});
await this.cache.keyByHash.remove(keyHash);
const ws = await this.db.primary.query.workspaces.findFirst({
where: (table, { eq }) => eq(table.id, data.key.workspaceId),
});
if (!ws) {
this.logger.error("fallback workspace not found either", {
workspaceId: data.key.workspaceId,
});
return Err(new DisabledWorkspaceError(data.key.workspaceId));
}
data.workspace = ws;
}

if ((data.forWorkspace && !data.forWorkspace.enabled) || !data.workspace?.enabled) {
return Err(new DisabledWorkspaceError(data.workspace.id));
return Err(new DisabledWorkspaceError(data.workspace?.id ?? "N/A"));
}

/**
Expand Down

0 comments on commit 8b37287

Please sign in to comment.