Skip to content

Commit

Permalink
fix: header fields in the api playground, and resetting user-entered …
Browse files Browse the repository at this point in the history
…token (#1816)
  • Loading branch information
abvthecity authored Nov 15, 2024
1 parent 873c18e commit 0bc99e5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FernButton, FernCollapse } from "@fern-ui/components";
import { useBooleanState } from "@fern-ui/react-commons";
import { useSetAtom } from "jotai/react";
import { ReactElement } from "react";
import { PLAYGROUND_AUTH_STATE_BEARER_TOKEN_ATOM } from "../../atoms";
import { PLAYGROUND_AUTH_STATE_BEARER_TOKEN_ATOM, PLAYGROUND_AUTH_STATE_OAUTH_ATOM } from "../../atoms";
import { useApiKeyInjectionConfig } from "../../services/useApiKeyInjectionConfig";
import { PlaygroundAuthorizationForm } from "./PlaygroundAuthorizationForm";
import { PlaygroundCardTriggerApiKeyInjected } from "./PlaygroundCardTriggerApiKeyInjected";
Expand All @@ -18,12 +18,14 @@ export function PlaygroundAuthorizationFormCard({
disabled,
}: PlaygroundAuthorizationFormCardProps): ReactElement | null {
const setBearerAuth = useSetAtom(PLAYGROUND_AUTH_STATE_BEARER_TOKEN_ATOM);
const setOAuth = useSetAtom(PLAYGROUND_AUTH_STATE_OAUTH_ATOM);
const isOpen = useBooleanState(false);
const apiKeyInjection = useApiKeyInjectionConfig();
const apiKey = apiKeyInjection.enabled && apiKeyInjection.authenticated ? apiKeyInjection.access_token : null;

const handleResetBearerAuth = () => {
setBearerAuth({ token: apiKey ?? "" });
setOAuth((prev) => ({ ...prev, userSuppliedAccessToken: "" }));
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function PlaygroundCardTriggerApiKeyInjected({
}
};

if (apiKey != null) {
if (apiKey != null && apiKey.trim().length > 0) {
return (
<FernCard className="rounded-xl p-4 shadow-sm mb-3" title="Login to send a real request">
<FernButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const PlaygroundEndpointForm: FC<PlaygroundEndpointFormProps> = ({
properties={headers}
extraProperties={undefined}
onChange={setHeaders}
value={headers}
value={formState?.headers}
types={types}
/>
</PlaygroundEndpointFormSection>
Expand Down

0 comments on commit 0bc99e5

Please sign in to comment.