# Frontend login from any page (via a shared plugin or controller)?

**URL:** <https://forum.getkirby.com/t/frontend-login-from-any-page-via-a-shared-plugin-or-controller/3117>\
**Category:** Questions\
**Tags:** v2\
**Created:** [January 25, 2016, 4:52am UTC](https://forum.getkirby.com/t/frontend-login-from-any-page-via-a-shared-plugin-or-controller/3117 "2016-01-25T04:52:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![drewbaren](https://avatars.discourse-cdn.com/v4/letter/d/a698b9/32.png) [@drewbaren](https://forum.getkirby.com/u/drewbaren)\
**Post date:** [January 25, 2016, 4:52am UTC](https://forum.getkirby.com/t/frontend-login-from-any-page-via-a-shared-plugin-or-controller/3117/1 "2016-01-25T04:52:35Z")

</div>

The frontend authentication solution described in the docs works perfectly, but I’d like to allow my site’s users to log in from any page within the site (homepage, article, archive, etc.) via a modal dialog box instead of navigating to the site’s `/login` page first.

I’ve seen @jenstornell’s [multiple posts](https://forum.getkirby.com/t/shared-controllers/1112) on this topic, but the solution doesn’t seem to allow `$user->login($password)` to work from anywhere.

I’ve also seen [this post](https://forum.getkirby.com/t/creating-a-controller-for-site-snippets-header-php/1036) about creating a controller for a snippet, and it’s suggested that a plugin be created instead with most of the same functionality. Unfortunately I haven’t been able to get frontend authentication to work with that method either, although my limited knowledge of PHP (outside of what Kirby has taught me) may be the cause of that.

Is there any way to log users in from any page without duplicating code for every page template/controller?

---

<div class="post-metadata">

**Author:** ![drewbaren](https://avatars.discourse-cdn.com/v4/letter/d/a698b9/32.png) [@drewbaren](https://forum.getkirby.com/u/drewbaren)\
**Post date:** [January 25, 2016, 4:54am UTC](https://forum.getkirby.com/t/frontend-login-from-any-page-via-a-shared-plugin-or-controller/3117/2 "2016-01-25T04:54:02Z")

</div>

[Link to the Docs solution](https://getkirby.com/docs/solutions/authentication#the-login) for reference. Couldn’t post more than 2 links in one post.

---

<div class="post-metadata">

**Author:** ![samnabi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/samnabi/32/5535_2.png) [@samnabi](https://forum.getkirby.com/u/samnabi)\
**Post date:** [January 25, 2016, 1:50pm UTC](https://forum.getkirby.com/t/frontend-login-from-any-page-via-a-shared-plugin-or-controller/3117/3 "2016-01-25T13:50:55Z")

</div>

I use a custom route mapped to **/login**. See line 171 of this config file. [https://github.com/samnabi/shopkit/blob/master/site/config/config.php](https://github.com/samnabi/shopkit/blob/master/site/config/config.php)

Note that the frontend login doesn’t work if you have caching turned on. Kirby will just serve the cached page as it was before you logged in.

Edit: for clarity, **/login** is the endpoint of a form that is included as a snippet on each page. So it works with a snippet and a route.

---

<div class="post-metadata">

**Author:** ![drewbaren](https://avatars.discourse-cdn.com/v4/letter/d/a698b9/32.png) [@drewbaren](https://forum.getkirby.com/u/drewbaren)\
**Post date:** [January 26, 2016, 4:51am UTC](https://forum.getkirby.com/t/frontend-login-from-any-page-via-a-shared-plugin-or-controller/3117/4 "2016-01-26T04:51:24Z")

</div>

Thank you @samnabi, that worked. Adding `cache::flush();` (mentioned [here](https://forum.getkirby.com/t/controlling-the-cache/464/2)) to the function seems to be a workaround, but flushing the whole cache seems wasteful. This will do for now. Thanks again!

---

<div class="post-metadata">

**Author:** ![possible\_books](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/possible_books/32/1707_2.png) [@possible\_books](https://forum.getkirby.com/u/possible_books)\
**Post date:** [June 9, 2017, 1:00pm UTC](https://forum.getkirby.com/t/frontend-login-from-any-page-via-a-shared-plugin-or-controller/3117/5 "2017-06-09T13:00:28Z")

</div>

Hello, i am just reading your answer because i also have the same issue. Unfortunately in your github file, the line 171 is not existing anymore. Would you care to post just the line of the routing here?

Thanks,  
Matthias

---

<div class="post-metadata">

**Author:** ![samnabi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/samnabi/32/5535_2.png) [@samnabi](https://forum.getkirby.com/u/samnabi)\
**Post date:** [June 9, 2017, 1:20pm UTC](https://forum.getkirby.com/t/frontend-login-from-any-page-via-a-shared-plugin-or-controller/3117/6 "2017-06-09T13:20:38Z")

</div>

The new location for that route is Line 9 here: [https://github.com/samnabi/shopkit/blob/master/site/plugins/shopkit/registry/routes.php#L10](https://github.com/samnabi/shopkit/blob/master/site/plugins/shopkit/registry/routes.php#L10)

---

<div class="post-metadata">

**Author:** ![possible\_books](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/possible_books/32/1707_2.png) [@possible\_books](https://forum.getkirby.com/u/possible_books)\
**Post date:** [June 9, 2017, 1:48pm UTC](https://forum.getkirby.com/t/frontend-login-from-any-page-via-a-shared-plugin-or-controller/3117/7 "2017-06-09T13:48:35Z")

</div>

Thanks a lot!  
You are doing the shopkit solution? Thats big on my list of improvements on my site… I still have to look into it 🙂

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:49pm UTC](https://forum.getkirby.com/t/frontend-login-from-any-page-via-a-shared-plugin-or-controller/3117/8 "2025-02-06T16:49:47Z")

</div>


