Read authorized-user data
A component needs to display information about the signed-in person.
Kinde · Hook
useKindeAuth provides Kinde authentication data inside a component. Use it to read authorized-user information or obtain an access token for protected API requests.
useKindeAuth is a React helper for accessing Kinde authentication data from a component. Destructure the authentication operation or data you need, such as getAccessToken or getUser, and use it within the component.
const { getAccessToken } = useKindeAuth();A Kinde authentication helper object; the page documents using it to access authorized-user Auth data and destructure getAccessToken.
import { useKindeAuth } from "@kindejs/react-core";
export default function Profile() {
const { getUser } = useKindeAuth();
const user = getUser();
return <p>{user?.given_name ?? "Not signed in"}</p>;
}Reads the current authorized user's Kinde Auth data in a React component.
A component needs to display information about the signed-in person.
A browser-side component calls a protected backend endpoint.
useKindeAuth is a React helper that exposes Kinde authentication data to components. It can be used to obtain authentication-related values or operations, such as the access token or current user data.
Follow-up: How would you use it for an API request? Obtain the access token, then send it in the request's Bearer authorization header.
Destructure getAccessToken from the hook and await it before making the request. Put the resulting token in the Authorization header using the Bearer scheme.
Follow-up: What should the API do with that token? Validate the bearer access token before serving the protected request.
The hook is used inside a component to retrieve Kinde Auth data for the currently authorized user. A component should account for the possibility that no authenticated user data is available.
Follow-up: How can the UI represent that state? Render an anonymous or sign-in state whenever the user value is absent.
getAccessTokenKinde Auth dataKindeProvider