-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
base: main
Are you sure you want to change the base?
WIP: fixing destination_url #33072
Conversation
@@ -67,6 +68,13 @@ export default class LoginMethod extends EmberObject { | |||
params["signup"] = true; | |||
} | |||
|
|||
const destinationUrl = cookie("destination_url"); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ path: "/" }
is the default.
There was a problem hiding this comment.
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:
discourse/app/assets/javascripts/discourse/app/controllers/login.js
Lines 155 to 162 in a9cf9ae
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); |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 :|
There was a problem hiding this comment.
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)
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me 👍
edd138c
to
6d92925
Compare
There was a problem hiding this 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
6d92925
to
1f37a23
Compare
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.