Unable to check if user is authenticated with showSignInAndRedirect in okta signin widget

Hi Team,

I want to check if user is authenticated on success of showSignInAndRedirect.
User is authenticated successfully, signin and redirect works fine. But on success i want to get session information by using oktaSignIn.authClient.session.exists(). And my control is not coming in onSuccess even after successful authentication. Please find below code for more information…

useEffect(() => {

if (!widgetRef.current) return false;
const widget = new OktaSignIn(config);
widget
 .showSignInAndRedirect({
    el: widgetRef.current
  })
  .then(onSuccess)
  .catch(onError);
return () => widget.remove();

}, [config, onSuccess, onError]);

can you please help me on this.

I don’t think you can catch this in the promise for showSignInAndRedirect. By using that method, you’re stating that you user will get redirected to Okta (via an /authorize URL for the clientId configured in your widget) and they will be sent back o the redirectUri.

If you call session.exists() on the callback route (the redirectUri) OR on another route the user is redirected to after the callback is completed (so your application can handle/store the user’s OIDC tokens), does it work?

Hi Andrea,

Thanks for your reply.
I was required to make changes for session management in UI.
But Now, i am doing session management on my service layer(sping boot okta’s API) than UI.

Regards,
Priyanka