
s7rw7 (s7rw7) asked a question.
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>
);
}

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!
I am using these versions. That article doesn't solve my problem
"@okta/okta-auth-js": "6.0",
"@okta/okta-react": "6.4",
@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?