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 and Flo4604 committed Oct 19, 2024
1 parent 3991af9 commit e81f507
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 @@ -357,8 +357,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 e81f507

Please sign in to comment.