Reindirizzamento dopo il login perde i parametri di query

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.

Guardando a:

Sembra che preserviamo i parametri di query per alcune percorsi predefiniti e questo schema è iniziato con questo commit (non sono sicuro del motivo per cui l’ho fatto… :confused:).

@sam dovremmo iniziare a supportare i parametri di query per tutti i percorsi? Non vedo alcuna implicazione di sicurezza nel consentire parametri di query su percorsi casuali.

Finché ciò viene attentamente revisionato, ritengo che sia opportuno estendere il supporto in questo caso.

Questo problema è stato risolto tramite: