# Redirect After Login

**URL:** <https://forums.losant.com/t/redirect-after-login/5566>\
**Category:** Help\
**Tags:** dashboard, workflow, cpf\
**Created:** [August 14, 2024, 8:36pm UTC](https://forums.losant.com/t/redirect-after-login/5566 "2024-08-14T20:36:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tanner\_Williams](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tanner\_Williams](https://forums.losant.com/u/Tanner_Williams)\
**Post date:** [August 14, 2024, 8:36pm UTC](https://forums.losant.com/t/redirect-after-login/5566/1 "2024-08-14T20:36:25Z")

</div>

`<p>To generate another report right now, <a href="https:// ~~~~.onlosant.com/devices/{{device.id}}?tab=dashboard" style="font-style: italic;">click here!</a></p>`  
Im using this link to send users to their dashboard where there is a button that lets them generate another dashboard report. When clicked if they dont already have a tab of the website open it takes them to login which is desirable, but then when they log in it doesn’t redirect to the original page they were heading to, just the main page dashboard, is there a simple solution to this or will i need to mess around in the login workflow a little

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [August 15, 2024, 2:55pm UTC](https://forums.losant.com/t/redirect-after-login/5566/2 "2024-08-15T14:55:16Z")

</div>

You will have to modify the login workflow. The most common solution is to add a `redirect` query parameter that instructs the login workflow where to go after they’ve logged in.

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [August 15, 2024, 3:14pm UTC](https://forums.losant.com/t/redirect-after-login/5566/3 "2024-08-15T15:14:15Z")

</div>

Getting the value of the redirect query parameter is challenging. You’ll need to update the `/devices/{deviceId}` endpoint configuration.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/2/21d1b1f47bc925ce3141095dd824cdac211cf543.png)

The full template is:

```auto
/login?redirect={{encodeURIComponent request.path}}%3F{{encodeURIComponent (queryStringEncode request.query)}}

```

Then in the login workflow, you’ll have the parameter available:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/7/7b0ba1372a81627730d71969221b7a46b2876a08.png)

The login workflow has a node labeled “Redirect to /”. You’ll need to modify that to instead redirect to `{{data.query.redirect}}`.

---

<div class="post-metadata">

**Author:** ![Tanner\_Williams](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tanner\_Williams](https://forums.losant.com/u/Tanner_Williams)\
**Post date:** [August 15, 2024, 3:20pm UTC](https://forums.losant.com/t/redirect-after-login/5566/4 "2024-08-15T15:20:04Z")

</div>

> [@Brandon\_Cannaday](#):
>
> Getting the value of the redirect query parameter is challenging. You’ll need to update the `/devices/{deviceId}` endpoint configuration.
> 
> ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/2/21d1b1f47bc925ce3141095dd824cdac211cf543.png)

what is this for? why do i change the device/device id route

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [August 15, 2024, 3:22pm UTC](https://forums.losant.com/t/redirect-after-login/5566/5 "2024-08-15T15:22:09Z")

</div>

Because that’s where your link is sending people:

```auto
<p>To generate another report right now, <a href="https:// ~~~~.onlosant.com/devices/{{device.id}}?tab=dashboard" style="font-style: italic;">click here!</a></p>

```

You are modifying that route to pass along the URL to the login page, so you can then redirect the user back to the link they originally clicked.

---

<div class="post-metadata">

**Author:** ![Tanner\_Williams](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tanner\_Williams](https://forums.losant.com/u/Tanner_Williams)\
**Post date:** [August 15, 2024, 3:23pm UTC](https://forums.losant.com/t/redirect-after-login/5566/6 "2024-08-15T15:23:09Z")

</div>

oh i see, i was thinking of a different approach give me one second, let me know if this seems reasonable

---

<div class="post-metadata">

**Author:** ![Tanner\_Williams](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tanner\_Williams](https://forums.losant.com/u/Tanner_Williams)\
**Post date:** [August 15, 2024, 3:24pm UTC](https://forums.losant.com/t/redirect-after-login/5566/7 "2024-08-15T15:24:59Z")

</div>

```auto
<p>To generate another report right now, <a href="https:// ~~~~.onlosant.com/login?redirect=devices/{{device.id}}?tab=dashboard" style="font-style: italic;">click here!</a></p>

```

![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/2/222a573382c6e5ba7e28f771714923cdc63ab644.png)

---

<div class="post-metadata">

**Author:** ![Tanner\_Williams](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tanner\_Williams](https://forums.losant.com/u/Tanner_Williams)\
**Post date:** [August 15, 2024, 3:30pm UTC](https://forums.losant.com/t/redirect-after-login/5566/8 "2024-08-15T15:30:57Z")

</div>

oh i see i lose the query param when it renders login

---

<div class="post-metadata">

**Author:** ![Tanner\_Williams](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tanner\_Williams](https://forums.losant.com/u/Tanner_Williams)\
**Post date:** [August 15, 2024, 3:31pm UTC](https://forums.losant.com/t/redirect-after-login/5566/9 "2024-08-15T15:31:21Z")

</div>

> [@Brandon\_Cannaday](#):
>
> Because that’s where your link is sending people:
> 
> ```auto
> <p>To generate another report right now, <a href="https:// ~~~~.onlosant.com/devices/{{device.id}}?tab=dashboard" style="font-style: italic;">click here!</a></p>
> 
> ```
> 
> You are modifying that route to pass along the URL to the login page, so you can then redirect the user back to the link they originally clicked.

This makes sense now

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [August 15, 2024, 3:31pm UTC](https://forums.losant.com/t/redirect-after-login/5566/10 "2024-08-15T15:31:27Z")

</div>

That would work. It’s a bit antithetical to normal web practices, but it is functional. You’ll want to do two things:

1. Add a leading slash before devices: `/devices...`.
2. Encode the nested query parameters: `?redirect=/devices/{{device.id}}{{encodeURIComponent '?tab=dashboard'}}`

---

<div class="post-metadata">

**Author:** ![Tanner\_Williams](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tanner\_Williams](https://forums.losant.com/u/Tanner_Williams)\
**Post date:** [August 15, 2024, 6:06pm UTC](https://forums.losant.com/t/redirect-after-login/5566/11 "2024-08-15T18:06:13Z")

</div>

If i wanted to do the redirect from device/{deviceId} is this on

```auto
https:// ~~~~.onlosant.com/devices/{{device.id}}?tab=dashboard

```

or do i need this “encodeURIComponent”

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [August 15, 2024, 6:14pm UTC](https://forums.losant.com/t/redirect-after-login/5566/12 "2024-08-15T18:14:50Z")

</div>

If you do the redirect on `/devices/{deviceId}` the template is above:

> [@Redirect After Login](https://forums.losant.com/t/redirect-after-login/5566/3):
>
> Getting the value of the redirect query parameter is challenging. You’ll need to update the /devices/{deviceId} endpoint configuration. The full template is: /login?redirect={{encodeURIComponent request.path}}%3F{{encodeURIComponent (queryStringEncode request.query)}} Then in the login workflow, you’ll have the parameter available: The login workflow has a node labeled “Redirect to /”. You’ll need to modify that to instead redirect to {{data.query.redirect}}.

It does use the `encodeURIComponent`. Adding the template above is general-purpose - it re-encodes whatever query parameters were used when the redirect occurred. So no matter how a user attempt to access `/devices/{deviceId}` (including your link), when they’re redirected to login, they will be redirected back appropriately. It’s not a bad feature to have in general.

---

<div class="post-metadata">

**Author:** ![Tanner\_Williams](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tanner\_Williams](https://forums.losant.com/u/Tanner_Williams)\
**Post date:** [August 15, 2024, 6:16pm UTC](https://forums.losant.com/t/redirect-after-login/5566/13 "2024-08-15T18:16:28Z")

</div>

I have the redirect  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/0/0334588307e7440471b31043186cdce9b3e0bad1.png)

here is the link to devices

```auto
<p>To generate another report right now, <a href="https:// ~~~~.onlosant.com/devices/{{device.id}}?tab=dashboard" style="font-style: italic;">click here!</a></p>

```

but when i click it takes me to login but with not query params

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/8/8b3c753e6d79421c1c2710805bb498bb15b6f3bf.png)

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [August 15, 2024, 6:18pm UTC](https://forums.losant.com/t/redirect-after-login/5566/14 "2024-08-15T18:18:33Z")

</div>

Can you please confirm which endpoint that redirect template was added to? The screenshot does not show it. There are two `/devices/{deviceId}` endpoints - one for GET and one for POST. You’ll need to add it to the GET endpoint.

---

<div class="post-metadata">

**Author:** ![Tanner\_Williams](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tanner\_Williams](https://forums.losant.com/u/Tanner_Williams)\
**Post date:** [August 15, 2024, 6:19pm UTC](https://forums.losant.com/t/redirect-after-login/5566/15 "2024-08-15T18:19:50Z")

</div>

thats probably what it was

---

<div class="post-metadata">

**Author:** ![Tanner\_Williams](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tanner\_Williams](https://forums.losant.com/u/Tanner_Williams)\
**Post date:** [August 15, 2024, 6:21pm UTC](https://forums.losant.com/t/redirect-after-login/5566/16 "2024-08-15T18:21:01Z")

</div>

thats probably what it was

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/3/38898923c850b2695ddc366b2c80823b7db7b8e6.png)  
fixed now its in GET

---

<div class="post-metadata">

**Author:** ![Tanner\_Williams](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tanner\_Williams](https://forums.losant.com/u/Tanner_Williams)\
**Post date:** [August 15, 2024, 6:22pm UTC](https://forums.losant.com/t/redirect-after-login/5566/17 "2024-08-15T18:22:07Z")

</div>

It still drops the query params though

---

<div class="post-metadata">

**Author:** ![Tanner\_Williams](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tanner\_Williams](https://forums.losant.com/u/Tanner_Williams)\
**Post date:** [August 15, 2024, 6:22pm UTC](https://forums.losant.com/t/redirect-after-login/5566/18 "2024-08-15T18:22:58Z")

</div>

never mind i put it in the wrong route twice

---

<div class="post-metadata">

**Author:** ![Tanner\_Williams](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tanner\_Williams](https://forums.losant.com/u/Tanner_Williams)\
**Post date:** [August 15, 2024, 6:24pm UTC](https://forums.losant.com/t/redirect-after-login/5566/19 "2024-08-15T18:24:55Z")

</div>

working now thank you a lot for the help

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [August 15, 2024, 6:25pm UTC](https://forums.losant.com/t/redirect-after-login/5566/20 "2024-08-15T18:25:08Z")

</div>

Glad we got it figured out!

[Next page](https://forums.losant.com/t/redirect-after-login/5566.md?page=2)
