swr-request-generator icon indicating copy to clipboard operation
swr-request-generator copied to clipboard

AxiosResponse Inside AxiosResponse

Open MonsignorEduardo opened this issue 1 year ago • 1 comments

This is maybe an error on my side. But for some reason the result type of trigger is an AxiosResponse inside an AxiosResponse.

export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
    const { trigger, isMutating } = useLoginForAccessTokenAuthPostRequest();
 
    const form = useForm<z.infer<typeof formSchema>>({
        resolver: zodResolver(formSchema),
        defaultValues: {
            username: "",
            password: "",
        },
    });

    async function onSubmit(values: z.infer<typeof formSchema>) {
        try {
            // According to the types this is a AxiosResponse<AxiosResponse<Token, any>, any> | undefined
            // But it is actually a AxiosResponse<Token, any> | undefined
            const result = await trigger({ body: { username: values.username, password: values.password } });

            if (!result) {
                throw new Error("No response");
            }
            console.dir(result);
            console.dir(result.data);
            // This does not work because the types are wrong
            const { access_token } = result.data.data;

This is my openAPI.json if you want to try openAPI.txt

MonsignorEduardo avatar Jun 02 '23 16:06 MonsignorEduardo