Skip to content

Commit

Permalink
fix: how authed edge nodes and redirects are computed (#1778)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Nov 5, 2024
1 parent 04549cb commit e159395
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
13 changes: 6 additions & 7 deletions packages/fdr-sdk/src/navigation/utils/findNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export function findNode(root: FernNavigation.RootNode, slug: FernNavigation.Slu
const apiReference =
found.parents.find(isApiReferenceNode) ?? (found.node.type === "apiReference" ? found.node : undefined);

// if the node is visible (becaues it's a page), return it as "found"
if (FernNavigation.isPage(found.node)) {
const parentsAndNode = [...found.parents, found.node];
const tabbedNodeIndex = parentsAndNode.findIndex((node) => node === tabbedNode);
Expand Down Expand Up @@ -124,13 +125,11 @@ export function findNode(root: FernNavigation.RootNode, slug: FernNavigation.Slu
return { type: "redirect", redirect: root.pointsTo };
}

const redirect = FernNavigation.hasRedirect(found.node)
? found.node.pointsTo
: currentVersion?.pointsTo ?? root.pointsTo;

if (redirect == null || redirect === slug) {
return { type: "notFound", redirect: undefined, authed: found.node.authed };
// if the node has a redirect, return it
if (FernNavigation.hasRedirect(found.node) && found.node.pointsTo != null) {
return { type: "redirect", redirect: found.node.pointsTo };
}

return { type: "redirect", redirect };
// if the node does not have a redirect, return a 404
return { type: "notFound", redirect: currentVersion?.pointsTo ?? root.pointsTo, authed: found.node.authed };
}
17 changes: 9 additions & 8 deletions packages/ui/docs-bundle/src/server/withRbac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
NavigationNodeParent,
Pruner,
hasMetadata,
isPage,
type NavigationNode,
type RootNode,
} from "@fern-api/fdr-sdk/navigation";
Expand Down Expand Up @@ -50,13 +49,15 @@ export function withBasicTokenAnonymousCheck(
return Gate.ALLOW;
}

if (
hasMetadata(node) &&
!isPage(node as NavigationNode) &&
withBasicTokenAnonymous(auth, addLeadingSlash(node.slug)) === Gate.DENY
) {
return Gate.DENY;
}
// Note: this was causing random edge nodes to show "authed=true"
// TODO: decide if we should keep this or remove it
// if (
// hasMetadata(node) &&
// !isPage(node as NavigationNode) &&
// withBasicTokenAnonymous(auth, addLeadingSlash(node.slug)) === Gate.DENY
// ) {
// return Gate.DENY;
// }

const predicate = rbacViewGate([], false);
return predicate(node as NavigationNode, parents);
Expand Down

0 comments on commit e159395

Please sign in to comment.