@authorizerdev/authorizer-react exports a hook which can be used in any child component for AuthorizerProvider.


It gives global state stored in the context, which can be used further in the component. It also returns few setter methods which can be used to manipulate the state.

Here is the complete list of state variables and functions that are returned by useAuthorizer hook.

Variable nameDescription
configRoot configuration object passed to AuthorizerProvider + backend configuration obtained via meta api
userIf not logged in this is null, else it includes all the user related information like email, given_name, family_name, picture, and more
tokenIf not logged in it is null else it is access token string which can be used to make authorized requests
loadingLoading state for the application to know if its fetching token or user profile data
setUserFunction to set user profile information. Accepts JSON object with all the possible profile values
setTokenFunction to set token. Accepts string with correct access token value
setLoadingFunction to set loading state. Accepts boolean value
setAuthDataFunction to set all the state data, user, token, loading, config. Accepts object with {user, token, config, loading} as value
logoutFunction to logout user
authorizerRefReference to authorizer-js instance which can be used to call functions exposed by authorizer-js

Sample Usage

import {useAuthorizer} from '@authorizerdev/authorizer-react`
const Component = () => {
const { user} = useAuthorizer();
if (!user) {
return null
return (