# Weiterleitung nach der Anmeldung verliert Query-Parameter

**URL:** https://meta.discourse.org/t/redirect-after-login-loses-query-params/121178
**Category:** Development
**Created:** [24. Juni 2019 um 15:57 UTC](https://meta.discourse.org/t/redirect-after-login-loses-query-params/121178 "2019-06-24T15:57:56Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![emanuele](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emanuele/32/142687_2.png) [@emanuele](https://meta.discourse.org/u/emanuele)
#### Post date: [24. Juni 2019 um 15:57 UTC](https://meta.discourse.org/t/redirect-after-login-loses-query-params/121178/1 "2019-06-24T15:57:56Z")

</div>

This is my route code:

```plaintext
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?

---

<div class="post-metadata">

### Author: ![emanuele](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emanuele/32/142687_2.png) [@emanuele](https://meta.discourse.org/u/emanuele)
#### Post date: [25. Juni 2019 um 10:47 UTC](https://meta.discourse.org/t/redirect-after-login-loses-query-params/121178/3 "2019-06-25T10:47:45Z")

</div>

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`).

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [26. Juni 2019 um 10:28 UTC](https://meta.discourse.org/t/redirect-after-login-loses-query-params/121178/4 "2019-06-26T10:28:33Z")

</div>

Do we want URL params? That seems highly unorthodox.

---

<div class="post-metadata">

### Author: ![emanuele](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emanuele/32/142687_2.png) [@emanuele](https://meta.discourse.org/u/emanuele)
#### Post date: [26. Juni 2019 um 10:33 UTC](https://meta.discourse.org/t/redirect-after-login-loses-query-params/121178/5 "2019-06-26T10:33:08Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [27. Juni 2019 um 07:24 UTC](https://meta.discourse.org/t/redirect-after-login-loses-query-params/121178/7 "2019-06-27T07:24:23Z")

</div>

> [@emanuele](#):
>
> 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.

I think it’s a bug in the core. I see a similar fix for SSO by @sam – [FIX: stop removing query params from destination url in sso · discourse/discourse@0b334cd · GitHub](https://github.com/discourse/discourse/commit/0b334cdf74e773f34d2cf7439d5118d248c342e3)

I will investigate and push a fix.

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [27. Juni 2019 um 08:09 UTC](https://meta.discourse.org/t/redirect-after-login-loses-query-params/121178/8 "2019-06-27T08:09:57Z")

</div>

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

> <https://github.com/discourse/discourse/blob/102be5a9e3a063bebe6a62927a102f84904a9bdf/app/assets/javascripts/discourse/routes/new-topic.js.es6#L58-L60>

@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.

---

<div class="post-metadata">

### Author: ![emanuele](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emanuele/32/142687_2.png) [@emanuele](https://meta.discourse.org/u/emanuele)
#### Post date: [27. Juni 2019 um 09:28 UTC](https://meta.discourse.org/t/redirect-after-login-loses-query-params/121178/9 "2019-06-27T09:28:13Z")

</div>

Hi 🙂

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 · GitHub](https://github.com/etamponi/discourse-keybase-proofs-plugin)

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.

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [27. Juni 2019 um 14:23 UTC](https://meta.discourse.org/t/redirect-after-login-loses-query-params/121178/10 "2019-06-27T14:23:10Z")

</div>

Wenn man sich das hier anschaut:

> <https://github.com/discourse/discourse/blob/863d8014d06a931b862ebe527e912483bee01786/app/controllers/static_controller.rb#L105>

scheint es, als würden wir Abfrageparameter für einige _vordefinierte_ Pfade beibehalten. Dieses Muster begann mit [diesem Commit](https://github.com/discourse/discourse/commit/d1632c1dbd256411bbb348f638bb7f5f61f05eae#diff-3c40c6a94911ca0e6513c39733048b22R75) (ich bin mir nicht sicher, warum ich das gemacht habe… 😕).

@Sam, sollen wir anfangen, Abfrageparameter für alle Pfade zu unterstützen? Ich sehe keine Sicherheitsauswirkung darin, Abfrageparameter auf beliebigen Pfaden zuzulassen.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [1. Juli 2019 um 00:44 UTC](https://meta.discourse.org/t/redirect-after-login-loses-query-params/121178/12 "2019-07-01T00:44:08Z")

</div>

> [@techAPJ](#):
>
> Sollten wir die Unterstützung von Query-Parametern für alle Pfade einführen? Ich sehe keine Sicherheitsauswirkung, wenn Query-Parameter auf zufälligen Pfaden erlaubt werden.

Solange dies sorgfältig geprüft wird, halte ich es für in Ordnung, die Unterstützung hier zu erweitern.

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [8. Juli 2019 um 04:05 UTC](https://meta.discourse.org/t/redirect-after-login-loses-query-params/121178/13 "2019-07-08T04:05:08Z")

</div>

Dieses Problem wurde nun über folgenden Link behoben:

> <https://github.com/discourse/discourse/commit/1708be4f27216392d429442524916bf8b6175443>
