swr-request-generator
swr-request-generator copied to clipboard
AxiosResponse Inside AxiosResponse
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