/** ******************************************************************************************************************* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. * ******************************************************************************************************************** */ import React, { useCallback, useState } from 'react'; import { ComponentStory, ComponentMeta } from '@storybook/react'; import Input from '@cloudscape-design/components/input'; import Button from '@cloudscape-design/components/button'; import FormField from '@cloudscape-design/components/form-field'; import Box from '@cloudscape-design/components/box'; import SpaceBetween from '@cloudscape-design/components/space-between'; import CognitoAuth, { CognitoAuthProps, useCognitoAuthContext } from '..'; import useSigv4Client from '../hooks/useSigv4Client'; import Container from '../components/Container'; import Alert from '@cloudscape-design/components/alert'; export default { component: CognitoAuth, title: 'Components/CognitoAuth/Sigv4Client', hidden: process.env.NODE_ENV !== 'development', } as ComponentMeta; const AuthenticatedContent = () => { const { onSignOut } = useCognitoAuthContext(); const [value, setValue] = useState(''); const [response, setResponse] = useState(); const [error, setError] = useState(); const client = useSigv4Client(); const handleFetch = useCallback(async () => { try { const response = await client(value); setResponse(await response.json()); } catch (err) { setError(err); } }, [client, value]); return ( The fetch call below will fail due to CORS error because storybook is running the call in a iframe. However, you can use this function to check whether the API call is created correctly from develop tool. setValue(event.detail.value)} placeholder="Enter APIGateway Fetch Url" /> {error && ( {error.message} )} {response && ( {JSON.stringify(response)} )} ); }; const Template: ComponentStory = (args: CognitoAuthProps) => { return ( ); }; export const CognitoAuthFlowWithSigv4Client = Template.bind({});