import {useMutation} from '@tanstack/react-query' import {useEffect, useState} from 'react' import {testUserPoolSignIn} from '@/api/cloudProxyClient' type Props = { poolId: string appClients: Array<{clientId: string; clientName: string}> loginLabel: string runtimeReachable: boolean } const KEY_CLAIMS = ['sub', 'email', 'cognito:username', 'cognito:groups', 'client_id', 'aud', 'token_use', 'exp'] export function CognitoSignInTest({poolId, appClients, loginLabel, runtimeReachable}: Props) { const [clientId, setClientId] = useState(appClients[0]?.clientId ?? '') const [username, setUsername] = useState('') const [password, setPassword] = useState('') useEffect(() => { if (!appClients.some((client) => client.clientId === clientId)) setClientId(appClients[0]?.clientId ?? '') }, [appClients, clientId]) const signIn = useMutation({ mutationFn: () => testUserPoolSignIn('aws', poolId, {clientId, username: username.trim(), password}), }) const result = signIn.data if (appClients.length === 0) return null return <>
Test sign-in
Signs in the way an app does and shows what is inside the tokens{signIn.error.message}
} {result?.outcome === 'rejected' &&Refused {result.code} {result.message}
Cognito wants another step {result.challengeName} {challengeHint(result.challengeName)}
Signed in. {result.expiresIn ? `The ID and access tokens are valid for ${Math.round(result.expiresIn / 60)} minutes.` : ''}
{title}
{key} | {formatClaim(key, claims[key])} |
|---|