gRPC authentication

This commit is contained in:
Gregory Schier
2024-02-17 23:47:28 -08:00
parent ab8503d87c
commit 8d29fad261
16 changed files with 246 additions and 123 deletions

View File

@@ -1,15 +1,16 @@
import { useUpdateGrpcRequest } from '../hooks/useUpdateGrpcRequest';
import { useUpdateHttpRequest } from '../hooks/useUpdateHttpRequest';
import type { HttpRequest } from '../lib/models';
import type { GrpcRequest, HttpRequest } from '../lib/models';
import { Input } from './core/Input';
import { VStack } from './core/Stacks';
interface Props {
requestId: string;
authentication: HttpRequest['authentication'];
interface Props<T> {
request: T;
}
export function BearerAuth({ requestId, authentication }: Props) {
const updateRequest = useUpdateHttpRequest(requestId);
export function BearerAuth<T extends HttpRequest | GrpcRequest>({ request }: Props<T>) {
const updateHttpRequest = useUpdateHttpRequest(request?.id ?? null);
const updateGrpcRequest = useUpdateGrpcRequest(request?.id ?? null);
return (
<VStack className="my-2" space={2}>
@@ -21,12 +22,19 @@ export function BearerAuth({ requestId, authentication }: Props) {
label="Token"
name="token"
size="sm"
defaultValue={`${authentication.token}`}
defaultValue={`${request.authentication.token}`}
onChange={(token: string) => {
updateRequest.mutate((r) => ({
...r,
authentication: { token },
}));
if (request.model === 'http_request') {
updateHttpRequest.mutate((r) => ({
...r,
authentication: { token },
}));
} else {
updateGrpcRequest.mutate((r) => ({
...r,
authentication: { token },
}));
}
}}
/>
</VStack>