okta / okta-oidc-js

okta-oidc-js
https://github.com/okta/okta-oidc-js
Other
395 stars 232 forks source link

useOktaAuth hook returns undefined #856

Open JJ78 opened 4 years ago

JJ78 commented 4 years ago

Regarding the documentation, the useOktaAuth hook is supposed to return some instances, in my case, it returns undefined, i don't get what i could miss, is it working for someone?

Thanks

I'm submitting this issue for the package(s):

I'm submitting a:

Current behavior

The useOktaAuth hook returns undefined

Expected behavior

The useOktaAuth hook should returns an authService object (and some other ones regarding the documentation)

Minimal reproduction of the problem with instructions

import { useOktaAuth } from "@okta/okta-react";

const Auth = () => {
  const data = useOktaAuth(); // data is undefined

  return (<h1>Hello World</h1>)
};

Extra information about the use case/user story you are trying to implement

Trying to build a custom login page withing a single page app

Environment

swiftone commented 4 years ago

Hi @JJ78, thanks for the report.

useOktaAuth() requires that your component be a descendent of the <Security> component (see https://github.com/okta/okta-oidc-js/tree/master/packages/okta-react#general-components and https://github.com/okta/okta-oidc-js/tree/master/packages/okta-react#available-hooks )

Is your <Auth> component rendering from some somewhere that is wrapped in <Security>?