登录后重定向丢失查询参数

This is my route code:

import { defaultHomepage } from "discourse/lib/utilities";

export default Discourse.Route.extend({
  beforeModel(transition) {
    if (!Discourse.User.current()) {
      $.cookie("destination_url", window.location.href);
      return this.replaceWith("login");
    }
    this.replaceWith(`/${defaultHomepage()}`).then(e => {
      Ember.run.next(() => {
        this.controllerFor("new-proof").send("openModal", transition.to.queryParams);
      });
    });
  },
});

The redirection to the login page works well, but after login, I get redirected to the correct controller but without the query parameters I had in the original request.

Is there a way around this that doesn’t involve using custom local storage entries/cookies? Am I doing something wrong?

I still don’t know how to preserve query params, but I have solved my own issue by using url params instead of query params (so the route is now /keybase-proofs/new-proof/:username/:kb_username/:sig_hash).

Do we want URL params? That seems highly unorthodox.

I assumed it was the right way to do it since the query params get lost in the transition. Perhaps I am doing something wrong with destination_url or the redirection to login?

I think it’s a bug in the core. I see a similar fix for SSO by @samFIX: stop removing query params from destination url in sso · discourse/discourse@0b334cd · GitHub

I will investigate and push a fix.

Note that redirect with query params survives login flow for http://localhost:9292/new-topic?title=beta. Relevant code can be found here:

@emanuele I will need more details.

  • What login method are you using (email/password, social, sso, etc)?
  • Can you provide a sample URL with query param?
  • Is your plugin live? Can I test it on my local instance?

Feel free to PM me above details.

Hi :slight_smile:

  1. I am using email/password
  2. http://localhost:9292/keybase-proofs/new-proof?kb_username=etamponi&username=emanuele.tamponi&sig_hash=puppa&kb_ua=foo
  3. The plugin code is at: GitHub - etamponi/discourse-keybase-proofs-plugin: Discourse Plugin for Keybase Proofs

To test it, replace the value of the username query param with your username. The route code is in routes/new-proof.js.es6 and it looks basically the same as the code you posted.

查看:

看起来我们只为几个预定义的路径保留查询参数,而这个模式始于 这个提交(我不确定当时为什么要这么做……:confused:)。

@sam 我们是否应该开始为所有路径支持查询参数?我认为在任意路径上允许查询参数不会带来任何安全隐患。

只要经过仔细审查,我认为在此扩展支持是可以的。

此问题已通过以下方式修复: