Why I get this error ?
Property 'jwt' does not exist on type '{ data: IAuthResponse; } | { error: FetchBaseQueryError | SerializedError; }'.
Property 'jwt' does not exist on type '{ data: IAuthResponse; }'.ts(2339)
I use RTK Query and want to handle my response:
Query.tsx
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { IAuthLoginForm } from '../../../components/Login/Model';
import { IAuthResponse } from './Model';
export interface IAuthResponse {
jwt: string;
name: string;
username: string;
profile_name: string;
}
export const AuthFlow = createApi({
reducerPath: 'AuthFlow',
baseQuery: fetchBaseQuery({ baseUrl: 'http://192.168.0.249:4000/' }),
endpoints: (builder) => ({
login: builder.mutation<IAuthResponse, IAuthLoginForm>({
query: (form) => ({
url: '/login',
method: 'POST',
body: form
})
})
})
});
export const { useLoginMutation } = AuthFlow;
Home.tsx
...
const [register, { data, error, isLoading }] = useLoginMutation();
const Submit = () => {
const response = await register('test');
if(response.jwt) {
// ERROR above jwt not exists on property
}
};
Why I get this error if I want to access .jwt ? I use it in my Model.. can anyone help me to solve this issue ?