# Protected routes and redirection after log in

**URL:** <https://forums.kodeco.com/t/protected-routes-and-redirection-after-log-in/62499>\
**Category:** Server Side Swift with Vapor\
**Created:** [February 18, 2019, 12:37pm UTC](https://forums.kodeco.com/t/protected-routes-and-redirection-after-log-in/62499 "2019-02-18T12:37:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaeltansg](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/michaeltansg/32/81494_2.png) [@michaeltansg](https://forums.kodeco.com/u/michaeltansg)\
**Post date:** [February 18, 2019, 12:37pm UTC](https://forums.kodeco.com/t/protected-routes-and-redirection-after-log-in/62499/1 "2019-02-18T12:37:27Z")

</div>

Is there a **secure** way to redirect users back to a protect route page after they have successfully logged in, instead of just sending back to the home index page?

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [February 18, 2019, 1:32pm UTC](https://forums.kodeco.com/t/protected-routes-and-redirection-after-log-in/62499/2 "2019-02-18T13:32:55Z")

</div>

@0xtim Can you please help with this when you get a chance? Thank you - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [February 18, 2019, 5:13pm UTC](https://forums.kodeco.com/t/protected-routes-and-redirection-after-log-in/62499/3 "2019-02-18T17:13:41Z")

</div>

@michaeltansg there are a number of ways to achieve it. You can store something in a cookie or the session to read after a login in and redirect to that. The flow would look something like:

- Custom redirect middleware saves the intended URL to a cookie or the session
- After login, see if something has been stored
- If so, ‘unsave the value’ and redirect to that, otherwise redirect to the homepage

Since it’s all done by redirects, if you redirect to a protected route, it will still be protected

---

<div class="post-metadata">

**Author:** ![thammaporn](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/thammaporn/32/81494_2.png) [@thammaporn](https://forums.kodeco.com/u/thammaporn)\
**Post date:** [September 28, 2019, 7:21pm UTC](https://forums.kodeco.com/t/protected-routes-and-redirection-after-log-in/62499/4 "2019-09-28T19:21:26Z")

</div>

@michaeltansg , @0xtim Thanks for sharing.
