React useOktaAuth is undefined

Hi, I’m having trouble getting the okta-react library to work for me. when I try to access useOktaAuth() I get undefined returned. I’m following this tutorial:
Most basic setup that should work:

import React, { useState, useEffect } from "react"
import { useOktaAuth } from "@okta/okta-react"
const AccountPage = () => {
  console.log(useOktaAuth()) // => undefined
  const { authState, authService } = useOktaAuth() // => TypeError: Cannot read property 'authState' of undefined

What am I missing here?

1 Like

Solved: The code should be wrapped around a BrowserRouter (from react-router-dom) and Security (@okta/okta-react) element.

1 Like