<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D54z00007rrzvpCAAOkta Classic EngineSingle Sign-OnAnswered2024-03-25T11:06:41.000Z2022-08-03T20:48:53.000Z2022-10-10T06:52:59.000Z

s7rw7 (s7rw7) asked a question.

Why authState is coming as null?

Please help me understand why authState is null

 

File:- index.js

const config = {

issuer: 'https://dev-95779092.okta.com/oauth2/default',

clientId: '0oa61lus53epM9Sju5d7', // for example, `0oa2am3kk1CraJ8xO1d7`

redirectUri: window.location.origin + '/login/callback'

};

 

var authClient = new OktaAuth(config);

 

root.render(

<BrowserRouter>

<Security oktaAuth={authClient} onAuthRequired={onAuthRequired} restoreOriginalUri={restoreOriginalUri}>

<Routes>

<Route path="/" exact={true} element={<App />}/>

<Route path="/login/callback" element={<Profile />}/>

<Route path="/logout" element={<Logout config={config} authClient={authClient}/>}/>

</Routes>

</Security>

</BrowserRouter>

);

 

 

File:- App.js

 

function App(props) {

const { authState, oktaAuth } = useOktaAuth();

function handleLogin(){

oktaAuth.signInWithRedirect();

console.log(authState);

console.log(oktaAuth);

}

 

function handleLogout(){

oktaAuth.signOut();

}

return (

<div className="App">

<h1>This is an App Component.</h1>

<button className="btn-login" onClick={handleLogin}>Login</button>

<button className="btn-logout" onClick={handleLogout}>Logout</button>

</div>

);

}


  • Paul S. (Okta, Inc.)

    Hello @s7rw7 (s7rw7)​  Thank you for reacting out to our Community!

     

    There was a similar question asked on our Dev Forum, please see if this answers your question:

    https://devforum.okta.com/t/authstate-is-null-after-redirecting-to-login-callback-in-react/15317

     

    My advice would be to leverage the Okta Developer forums for this type of questions and take advantage of their expertise.

    https://devforum.okta.com/

     

    Hope this helps and if this answered your question, please mark this as Best Answer! 

    Expand Post
    • s7rw7 (s7rw7)

      I am using these versions. That article doesn't solve my problem

      "@okta/okta-auth-js": "6.0",

      "@okta/okta-react": "6.4",

  • r23ge (r23ge)

    @s7rw7 (s7rw7)​ I have the same problem as you. I also use the 6.X version, which prompts me that authState is null. I was wondering if you solved your problem?

This question is closed.
Loading
Why authState is coming as null?