Skip to main content
Version: 4.xx.xxSource Code

useGetIdentity

caution

This hook can only be used if the authProvider is provided.

useGetIdentity calls the getIdentity method from the authProvider under the hood.

It returns the result of react-query's useQuery which includes many properties, some of which being isSuccess and isError. Data that is resolved from the getIdentity will be returned as the data in the query result.

Usage​

useGetIdentity can be useful when you want to get user information anywhere in your code.

Let's say that you want to show the user's name.

We have a logic in authProvider's getIdentity method like below.

import type { AuthBindings } from "@refinedev/core";

const authProvider: AuthBindings = {
// ---
getIdentity: async () => {
return {
id: 1,
fullName: "Jane Doe",
};
},
// ---
};

You can access identity data like below.

import { useGetIdentity } from "@refinedev/core";

export const User: React.FC = () => {
const { data: identity } = useGetIdentity<{
id: number;
fullName: string;
}>();

return <span>{identity?.fullName}</span>;
};