workos / authkit

The world's best login box powered by WorkOS and Radix.
https://authkit.com
MIT License
2.3k stars 89 forks source link

Send the user to a specific place after login/sign up #37

Closed jmoseley closed 2 months ago

jmoseley commented 2 months ago

I have a flow where, in certain circumstances, I need the user to be sent to an alternate page after the login flow is complete.

If this was fixed, I would set the returnPathname property for the callback handler. But I need to be able to pass some state through the login flow so I can send the user to the right place depending on how they arrived at the app.

For example:

  1. User arrives at myapp.com/integration?integration_id=foo
  2. If user is authenticated, flow proceeds from there
  3. If user is not authenticated, direct to login screen
  4. After login, user needs to be returned to myapp.com/integration?integration_id=foo, and flow proceeds as usual

For step 4, I am having trouble figuring out how I can pass through the state necessary to redirect the user back to the right place.

PaulAsjes commented 2 months ago

I'm assuming you're using one of the SDKs rather than the Next.js or Remix libraries, if not let me know!

You can use the state parameter in the get authorization URL API route to record data like the return path. Then once the user has been authenticated in your callback route you can redirect them to the URL you saved in state.

jmoseley commented 2 months ago

I'll give that a shot, thanks.