# oktaAuth not showing authenticated after login

**URL:** <https://devforum.okta.com/t/oktaauth-not-showing-authenticated-after-login/12490>\
**Category:** Questions\
**Created:** [January 13, 2021, 5:09pm UTC](https://devforum.okta.com/t/oktaauth-not-showing-authenticated-after-login/12490 "2021-01-13T17:09:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![msch92](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/msch92/32/2519_2.png) [@msch92](https://devforum.okta.com/u/msch92)\
**Post date:** [January 13, 2021, 5:09pm UTC](https://devforum.okta.com/t/oktaauth-not-showing-authenticated-after-login/12490/1 "2021-01-13T17:09:22Z")

</div>

Hey all,

I have a basic React app where `oktaAuth` (from the `useOktaAuth` hook) is not showing expected values after a successful login.

The app structure is as follows:

```auto
// App.tsx

const oktaAuth = new OktaAuth({
    issuer: `https://dev-xxx.okta.com/oauth2/default`, // hidden for privacy
    clientId: 'xxx', // hidden for privacy
    redirectUri: `${window.location.origin}/dashboard`,
 })

function App() {
   const onAuthRequired = function() {
        history.push('/signin')
    }
    return (
    <Security oktaAuth={oktaAuth} onAuthRequired={onAuthRequired} >
          <Route path={SIGNIN}>
            <SignIn />
          </Route>
          <Route path={DASHBOARD}>
            <Dashboard />
        </Route>
    </Security>
    )
}

```

```auto
// SignIn.tsx
function SignIn() {
    const { oktaAuth } = useOktaAuth();

    const [username, setUsername] = useState<string | undefined>('');
    const [password, setPassword] = useState<string | undefined>('');

    const handleSubmit = (e:{[key:string]:any}) => {
        e.preventDefault();
        if (!username || !password) return;

        oktaAuth.signInWithCredentials({ username, password })
        .then((res) => {
          const { sessionToken } = res;
          if (res.status === 'SUCCESS') {
            oktaAuth.session.setCookieAndRedirect(sessionToken, `${window.location.origin}/dashboard`);
          }
        })
        .catch((err) => console.log('Found an error', err));
      };

    return (
    <div className={classes.page}>
       <FormBox title="Sign In" onSubmit={handleSubmit}>
        ...
      </FormBox>
   </div>
  
    );
}

```

on `Dashboard.tsx` after successful login and redirect, we log `oktaAuth` as follows:

```auto
    const { authState, oktaAuth } = useOktaAuth();
    console.log( authState)

```

however the values are

```auto
{isPending: true, isAuthenticated: false, idToken: null, accessToken: null, refreshToken: null}accessToken: nullidToken: nullisAuthenticated: falseisPending: truerefreshToken: null __proto__ : Object

```

```auto
{accessToken: undefined, idToken: undefined, refreshToken: undefined, isPending: false, isAuthenticated: false}accessToken: undefinedidToken: undefinedisAuthenticated: falseisPending: falserefreshToken: undefined __proto__ : Object

```

I can see that there are no cookies set locally, however they are set on [https://dev-xxx.okta.com/oauth2/default](https://dev-xxx.okta.com/oauth2/default).

Is something wrong with my approach?

Thank you

---

<div class="post-metadata">

**Author:** ![gpadma](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@gpadma](https://devforum.okta.com/u/gpadma)\
**Post date:** [January 13, 2021, 7:52pm UTC](https://devforum.okta.com/t/oktaauth-not-showing-authenticated-after-login/12490/2 "2021-01-13T19:52:44Z")

</div>

Hi!

At the end of signInWithRedirect and session.setSessionCookieAndRedirect, okta session cookie would be set in the user’s browser. However, the app would not have got the tokens. For obtaining tokens, you would have to use a method like [token.getWithoutPrompt](https://github.com/okta/okta-auth-js#tokengetwithoutpromptoptions).

---

<div class="post-metadata">

**Author:** ![msch92](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/msch92/32/2519_2.png) [@msch92](https://devforum.okta.com/u/msch92)\
**Post date:** [January 14, 2021, 12:16am UTC](https://devforum.okta.com/t/oktaauth-not-showing-authenticated-after-login/12490/3 "2021-01-14T00:16:58Z")

</div>

@gpadma thank you! something like

```auto
        oktaAuth.signInWithCredentials({ username, password })
        .then((res) => {
          const { sessionToken } = res;
          if (res.status === 'SUCCESS') {
            oktaAuth.token.getWithoutPrompt({
                responseType: 'id_token',
                sessionToken,
              })
              .then((res) => {
                const { tokens } = res;
                console.log('tokens', tokens)
              
                oktaAuth.tokenManager.setTokens(tokens);
                history.push('/dashboard');

              })
              .catch((err) => {
                  console.log('err', err)
              });
          }
        })
        .catch((err) => console.log('Found an error', err));

```

works as expected. is `setCookieAndRedirect` necessary for our purposes at all?

---

<div class="post-metadata">

**Author:** ![rajnadimpalli](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@rajnadimpalli](https://devforum.okta.com/u/rajnadimpalli)\
**Post date:** [January 14, 2021, 2:45am UTC](https://devforum.okta.com/t/oktaauth-not-showing-authenticated-after-login/12490/4 "2021-01-14T02:45:15Z")

</div>

> [@msch92](#):
>
> setCookieAndRedirect

setCookieAndRedirect is not required for your use case as you are using OIDC for the integration. It is normally used for integrations which don’t support OIDC.

You can either use getWithoutPrompt or getWithRedirect. getWithRedirect is better as that doesn’t have dependency on third party cookies.

Thanks,  
Raj

---

<div class="post-metadata">

**Author:** ![carolinafbarros](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@carolinafbarros](https://devforum.okta.com/u/carolinafbarros)\
**Post date:** [January 28, 2022, 9:32am UTC](https://devforum.okta.com/t/oktaauth-not-showing-authenticated-after-login/12490/5 "2022-01-28T09:32:09Z")

</div>

How can I obtain the tokens (using the [token.getWithoutPrompt](https://github.com/okta/okta-auth-js#tokengetwithoutpromptoptions)) when I’m using the method `oktaAuth.signInWithRedirect()`?

The method `oktaAuth.signInWithRedirect()` returns a promise void.

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [January 28, 2022, 8:09pm UTC](https://devforum.okta.com/t/oktaauth-not-showing-authenticated-after-login/12490/6 "2022-01-28T20:09:41Z")

</div>

Take a look at the ref for the [signInWithRedirect()](https://github.com/okta/okta-auth-js#signinwithredirectoptions) method in the AuthJS docs. You’ll notice that the sample uses our [handleLoginRedirect()](https://github.com/okta/okta-auth-js#handleloginredirecttokens-originaluri) method, which handles the token storage for you:

```auto
if (authClient.isLoginRedirect()) {
  try {
    await authClient.handleLoginRedirect();
  } catch (e) {
    // log or display error details
  }
} else if (!await authClient.isAuthenticated()) {
  // Start the browser based oidc flow, then parse tokens from the redirect callback url
  authClient.signInWithRedirect();
} else {
  // User is authenticated
}

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [February 12, 2024, 9:06pm UTC](https://devforum.okta.com/t/oktaauth-not-showing-authenticated-after-login/12490/7 "2024-02-12T21:06:23Z")

</div>

Closed on February 12, 2024, 9:06pm UTC

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
