Skip to content

Auth User Data

Get the Authorized user's state from any Component simply by using HOC or Hooks

  • To get the Authorized user's state from Higher Order Components, use withAuthUser
  • To get the Authorized user's state using React Hooks, use useAuthUser

Using Hooks

import {useAuthUser} from 'react-auth-kit'

Demo

import React from 'react'
import {useAuthUser} from 'react-auth-kit'

const SomeComponent = () => {
    const auth = useAuthUser()

    return(
        <div>
            Hello {auth().user}
        </div>
    )
}

Using Higher Order Component

import {withAuthUser} from 'react-auth-kit'

Demo

import React from 'react'
import {withAuthUser} from 'react-auth-kit'

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

export default withAuthUser(SomeComponent)

— 🔑 —

React Auth Kit is Apache 2.0 License code