Redirect After Login

<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

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.

1 Like

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

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

Because that’s where your link is sending people:

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

1 Like

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

<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

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

This makes sense now

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'}}
1 Like

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

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

or do i need this “encodeURIComponent”

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

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.

I have the redirect
image

here is the link to devices

<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

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.

thats probably what it was

thats probably what it was


fixed now its in GET

It still drops the query params though

never mind i put it in the wrong route twice

working now thank you a lot for the help

Glad we got it figured out!

1 Like