Link to sign up then to authenticated content

I want to implement the following functionality:

  1. A potential, not-signed-up user clicks on a link to authenticated content in my web app.
  2. The user is automatically taken to my sign up page.
  3. The user signs up and is then taken to the linked page.
  4. I use React Router.

I have no idea really how to approach this. Any advice would be much appreciated.

Thanks,
Chuck

So I assume you are asking for an overall suggestion only for route redirection.

If that’s the case you can make use of history.goBack() or <Redirect to={} /> provided by React Router. I strongly recommend you to check this code snippet provided by React Router guys.

However, if you are asking for an overall implementation strategy starting from user check in app level, there are different strategies for that.

The link provided by @cyardimci gives a nice example. That is a fancy way of replacing the content page with the signup forms if the user is not signed in, then when the user is logged in the sign up forms will automatically be replaced with the content.

Similar to:

 {Meteor.userId() ? <SignInForm /> : <AuthenticatedContent />}

Might not be so easy if the SignIn involves confirming a valid email address.

Another way could be to set a localStorage variable with the URL to be redirected to, then when the user successfully signs up in you could history.push() to the new URL.