Skip to content

Auth Header

Get the Auth Header for future requests from any Component simply by using HOC or Hooks

  • For Functional Components, you can use useAuthHeader() hook inside any components
  • For class-based components, you can wrap the component inside withAuthHeader() HOC function.

Hook

Import

Import useAuthHeader in your app
import useAuthHeader from 'react-auth-kit/hooks/useAuthHeader';

Usage

SecureComponent.js
import React from 'react'
import useAuthHeader from 'react-auth-kit/hooks/useAuthHeader';

const SomeComponent = () => {
    const authHeader = useAuthHeader()

    return(
        <div>
            {authHeader}
        </div>
    )
}

Higher Order Component

Import

Import withAuthHeader in your app
import withAuthHeader from 'react-auth-kit/hoc/withAuthHeader';

Usage

SecureComponent.js
import React from 'react';
import withAuthHeader from 'react-auth-kit/hoc/withAuthHeader';

class SomeComponent extends React.Component {
    render(){
        return (
            <div>
                {this.props.authHeader}
            </div>
        )
    }
}

export default withAuthHeader(SomeComponent)

API


— 🔑 —

React Auth Kit is MIT License code