I think I misunderstand the purpose of RTK Query.
Basically I have an app, where I need to login using email and password, this request returns me userId. That is my API file
export const accountApi = createApi({
reducerPath: 'accountApi',
baseQuery: fetchBaseQuery({ baseUrl: location.origin }),
endpoints: (builder) => {
getUserId: builder.query({
query: ({ emailValue, passwordValue }) => ({
url: `/users`,
headers: {
'authentication-failure-code': 403,
'Authorization': `Basic btoa(`${(emailValue)}:${(passwordValue)}`)`,
}
responseHandler: (response) => response.text(),
})
transformResponse: (response) => applyDataCallback(response),
}),
}
},
On my SignIn page this request returns me userID, which I need to use literally for all future request in my app. But how I can get this id in another component after logging in if I obviously don't have email and password?
export default function MainApp() {
const { data: userId } = useGetUserIdQuery();
useGetUserIdQuery expects such params as login and pass, and of course code like this causes an errors.
useSelector also won't work here, because it gives only not normalized cache.
Am I missing some basics here? Or should I use just simple RTK for saving my id?