withAuth

The withAuth function is a higher-order component that injects an auth prop into the component given to it as an argument. The auth prop has a reference to the logged in user, so this function is useful for wrapping components that use or display info based on the current user.

Import

import { withAuth } from '@staqjs/client'

API

The auth prop supplied by withAuth supports the following properties.

currentUser

type: object

An object representing the logged in user, or undefined if no one is logged in.

onLogout

type: function

signature: (() => void) => void

This method takes a function to call after logout has been performed. This is useful for redirecting to home or a signin page after clicking logout.

Example:

const onClickSignOut = () => {
  auth.onLogout(() => {
      history.push('/')
  })
  firebase.doSignOut()
}

Example Usage

import { withAuth } from '@staqjs/client'

function Dashboard(props) {
  const { auth } = props

  // ... code ...
}

export default withAuth(Dashboard)