Skip to content

useAuthHeader

Import

import useAuthHeader from 'react-auth-kit/hooks/useAuthHeader';

Function Signature

useAuthHeader(): string | null

Auth Header React Hook

Call the hook, to get the auth header inside the component

Format: type token (authType<space>authToken)

Returns

string | null

If the user is authenticated, then 'auth.type auth.token' is returned. If the user is not authenticated, then null is returned.

Example

Here is a simple example

import useAuthHeader from 'react-auth-kit/hooks/useAuthHeader'

const Component = () => {
 const authHeader = useAuthHeader();
 const headers = {
   'Authorization': authHeader
 }
 // use the headers in the network request
 ...
}

Throws

AuthError Thrown if the Hook is used outside the Provider Scope.

Defined in

hooks/useAuthHeader.ts


— 🔑 —

React Auth Kit is MIT License code