[Feature/Fix] Redirect users back to previous URL upon sign in #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
tl;dr
Fix
Currently the
state
parameter is being set to a random 20 character string upon being redirected to WorkOS for authentication. The state parameter is being used as an extra "check" to ensure the log in is valid with theensureStateIsValid
method. Per WorkOS, we don't need to use the state parameter to ensure any integrity and can use it to pass information to restore state:Additionally, WorkOS can pass a state parameter back to your application that you may use to encode arbitrary information to restore your application state between the redirects.
Unfortunately, the current random string state breaks the invitation system:
state
variable set from hitting the /login route.This PR fixes this by not enforcing that the
state
variable is present. I'm building out a private application where there is no public registration and users will be invited through WorkOS.Redirecting/Setting default route
This PR encode the previous URL upon hitting the
/login
route and will allow us to redirect users back. For example if an unauthenticated user goes to https://contoso.test/settings, they'll be redirected to WorkOS for auth, and then back to the settings page.Currently the WorkOS scaffolding sets the default route to
dashboard
.With this PR the above still works fine, but if the user wants the scaffolding to redirect back to the previous URL they can update their login route to while also setting a default location: