Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AxiosResponse Inside AxiosResponse #18

Open
MonsignorEduardo opened this issue Jun 2, 2023 · 1 comment
Open

AxiosResponse Inside AxiosResponse #18

MonsignorEduardo opened this issue Jun 2, 2023 · 1 comment

Comments

@MonsignorEduardo
Copy link

MonsignorEduardo commented Jun 2, 2023

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

@teobler
Copy link
Owner

teobler commented Sep 11, 2024

You may used wrong useMutationRequest function, the type returned by trigger should be controlled by useMutationRequest function, you can refer to example folder to get more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants