How to redirect users to custom web page after sign in from okta sign in widget?

Hi All,

I’m building a React web app.
I used Okta sign in widget code for setting up sign in page.
Once user provides the credentials and click on Sign in button its re-directing to Okta userHome page,
but i need to re-direct it to custom web page, instead of Okta userHome page.
Can someone help me with this.
Thanks in advance.

var oktaSignIn = new OktaSignIn(config);
        oktaSignIn.renderEl(
  // Assumes there is an empty element on the page with an id of 'osw-container'
  {el: '#okta-login-container'},

  function success(res) {
    var url = window.location.href ;
    // The user has successfully completed the authentication flow
    if (res.status === 'SUCCESS') {
              if(url.includes("sometext")){
                res.session.setCookieAndRedirect('custom-redirect-page');
                } else {
                res.session.setCookieAndRedirect('go-to-okta-anyway');
                }
      return;
    }

  },

  function error(err) {
    //handle errors
  }

This is how I redirect, after a success response we set a cookie redirect.

Thanks for the response.
where we need to set this exactly?
is it inside the Okta signin widget code or this is all together in a separate class?

This is in the javascript of the okta widget, so on the page where you want the okta widget to render.

I am using the SAML application, and self hosted sign in Widget.

using this example, I am setting the “App Embed Link in SAML App General page” link into res.session.setCookieAndRedirect.

how it will be redirected back to referrer page from where the user requested to login?