Skip to content

WIP: fixing destination_url #33072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

WIP: fixing destination_url #33072

wants to merge 4 commits into from

Conversation

ZogStriP
Copy link
Member

@ZogStriP ZogStriP commented Jun 4, 2025

Since the introduction of dedicated login and signup pages (as opposed to modals), we've been seeing reports of issues where visitors aren't redirected back to the "page" they were at when they initiated the authentication process.

Since we have a bazillion of ways a user might authenticate (credentials, social logins, SSO, passkeys, discourse connect, etc...), it's really hard to know what a change will impact.

The goal of this PR is to "simplify" the way we handle this "redirection back to origin" by leveraging the use of a single destination_url cookie set on the client-side.

@@ -67,6 +68,13 @@ export default class LoginMethod extends EmberObject {
params["signup"] = true;
}

const destinationUrl = cookie("destination_url");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using an "external login" method (aka. social logins), we pass the "origin" to the server (omniauth).

removeCookie("destination_url");
window.location.assign(destinationUrl);
} else if (this.referrerTopicUrl) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.referrerTopic is redundant now that we use the destination_url cookie.


if (ssoDestinationUrl) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure why this uses a different cookie 🤔 This is the main reason this PR is a draft because I don't understand the consequences of this change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious if @OsamaSayegh or @davidtaylorhq remember the reason for having sso_destination_url vs destination_url.

@@ -453,7 +453,7 @@ export default class SignupPageController extends Controller {
const destinationUrl = this.authOptions?.destination_url;

if (!isEmpty(destinationUrl)) {
cookie("destination_url", destinationUrl, { path: "/" });
cookie("destination_url", destinationUrl);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ path: "/" } is the default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also ensure that destinationUrl is subfolder aware?

Unless there's a piece of logic somewhere else modifying the cookie, it doesn't seem like it takes subfolders into account:

if (ssoDestinationUrl) {
removeCookie("sso_destination_url");
window.location.assign(ssoDestinationUrl);
} else if (destinationUrl) {
removeCookie("destination_url");
window.location.assign(destinationUrl);
} else if (this.referrerTopicUrl) {
window.location.assign(this.referrerTopicUrl);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes you think the behavior changed when it comes to handling subfolder? 🤔

@@ -278,11 +278,12 @@ export default class ApplicationRoute extends DiscourseRoute {

handleShowCreateAccount(createAccountProps) {
if (this.siteSettings.enable_discourse_connect) {
const returnPath = encodeURIComponent(window.location.pathname);
const returnPath = cookie("destination_url")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When Discourse Connect is enabled, we have a slightly different behavior for the return path when there's a destination_url cookie. I applied the same behavior when going through the signup process too.

This is the 2nd reason why this PR is a draft as I'm not 100% sure the impact this change has 🤔

"referrerTopicUrl",
this.internalReferrer || document.referrer
);
cookie("destination_url", this.internalReferrer || document.referrer);
Copy link
Member Author

@ZogStriP ZogStriP Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the destination_url cookie instead of relying on a controller's property.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me 👍

@@ -10,7 +12,11 @@ export default class SignupRoute extends DiscourseRoute {

authComplete = false;

beforeModel() {
beforeModel({ from }) {
if (from) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applies the same "store the origin url in a cookie" behavior we do when login in, but for the signup process.

@@ -21,7 +21,7 @@
request.session[:auth_reconnect] = !!request.params["reconnect"]

# If the client provided an origin, store in session to redirect back
request.session[:destination_url] = request.params["origin"]
request.session[:destination_url] = request.params["origin"] if request.params["origin"].present?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just QoL change.

@@ -32,6 +32,9 @@ def register_middleware(omniauth)
opts[:client_id] = SiteSetting.google_oauth2_client_id
opts[:client_secret] = SiteSetting.google_oauth2_client_secret

# NOTE: uncomment when testing locally
# opts[:redirect_uri] = "http://localhost:4200/auth/google_oauth2/callback"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a while to figure that one out :|

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can fix this properly: #33102

(and then drop these comments)

Copy link
Contributor

@pmusaraj pmusaraj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the right approach to me.


if (ssoDestinationUrl) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious if @OsamaSayegh or @davidtaylorhq remember the reason for having sso_destination_url vs destination_url.

"referrerTopicUrl",
this.internalReferrer || document.referrer
);
cookie("destination_url", this.internalReferrer || document.referrer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me 👍

@ZogStriP ZogStriP force-pushed the fix-destination-url branch from edd138c to 6d92925 Compare June 5, 2025 13:29
Copy link
Contributor

@pmusaraj pmusaraj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZogStriP let's try this out!

Any chance we can add a system spec here for:

  • visit a topic page or category
  • click login
  • auth using an oauth provider
  • once auth completes, expect user to land in the topic page or category

@ZogStriP ZogStriP force-pushed the fix-destination-url branch from 6d92925 to 1f37a23 Compare June 6, 2025 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants