GetIdentity is called twice
I am using classic authProvider with getIdentity method. Inside one of the components I use:
const { data: user } = useGetIdentity<IIdentity | null>();
When I refresh application, getIdentity inside authProvider is called twice. If I comment out this line, getIdentity is still called once. Could it be that getIdentity is called somewhere in the background? If so, how could I access it's value inside my component so I don't have to make two requests?2 Replies
Hi @Tacho. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The
getIdentity
method is indeed called by the Refine framework itself. As per the Refine documentation (https://refine.dev/docs/guides-concepts/usage-with-existing-projects#optional-methods), the getIdentity
method is used to enable the useGetIdentity
hook, which is used for rendering current user information in the header of UI Integration layouts.
This could be the reason why you see the getIdentity
method being called even when you comment out your useGetIdentity
hook. The framework itself is making a call to getIdentity
to fetch user information for the header.
To avoid making two requests, you can utilize the useGetIdentity
hook provided by Refine. This hook calls the getIdentity
method from the authProvider
under the hood and returns the result of react-query
's useQuery
. The data resolved from the getIdentity
will be returned as the data
in the query result. Here's how you can use it:
In this example, identity
will hold the data returned by your getIdentity
method. You can use this data anywhere in your component without having to call getIdentity
again.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@537772056847187988> kapa.ai is still learning and improving, please let us know how it did by reacting below