Redirect to custom start page rather than app origin after sign in

Based on the documentation, it seems pretty straightforward to do redirect someone to a route other than the origin for an app. Per the documentation here, it says:

redirectToSignIn(redirectURI: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), manifestURI: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), scopes: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)): void

Parameters

redirectURI  `(String = `${window.location.origin}/`` ) The location to which the identity provider will redirect the user after the user approves sign in.

manifestURI  `(String = `${window.location.origin}/manifest.json`` ) Location of the manifest file.

scopes  `(Array = DEFAULT_SCOPE` ) Defaults to requesting write access to this app's data store. An array of strings indicating which permissions this app is requesting.

This almost works. After signin, I’m redirected to the custom path I supply with the auth token still appended. Then the app redirects back to the origin. I can’t find anything in my code that is causing this, so I’m wondering if the redirectToSignIn parameters are working properly. Has anyone got this working?

1 Like

On app.co, we have an admin dashboard with Blockstack auth. Here is where we call redirectToSignIn:

We redirect to /admin, and I’ve never had a problem with it thus far. The way you describe the behavior makes me think it’s in your app code, because I haven’t seen any code in blockstack.js that redirects after handling sign in. But I could be wrong!

1 Like

Thanks, Hank. That’s exactly how I’m handling it. I’ll get some code snippets and maybe a recording of what’s happening to be sure. Glad to know the method is working for someone, though.

Resolved thanks you @hank’s awesomeness.

1 Like

@jehunter5811 How was it solved?

The handlePendingSignIn method needs to know where the user should be directed once the userData is loaded. So both redirectToSignIn and handlePendingSignIn need customization.

So my solution looks like this:

if (isSignInPending()) {
      handlePendingSignIn().then((userData) => {
        window.location = window.location.href.split('&')[0];
      });
    }

The window.location.href.split(’&’)[0] is just parsing the redirect URL minus the authResponse token.