# Frontend-Authentication for specific user role

**URL:** <https://forum.getkirby.com/t/frontend-authentication-for-specific-user-role/5635>\
**Category:** Questions\
**Tags:** v2\
**Created:** [October 30, 2016, 1:21pm UTC](https://forum.getkirby.com/t/frontend-authentication-for-specific-user-role/5635 "2016-10-30T13:21:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielschmid](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/danielschmid/32/349_2.png) [@danielschmid](https://forum.getkirby.com/u/danielschmid)\
**Post date:** [October 30, 2016, 1:21pm UTC](https://forum.getkirby.com/t/frontend-authentication-for-specific-user-role/5635/1 "2016-10-30T13:21:14Z")

</div>

I’ve created a Frontend-Authentication on my website and i would allow authentication only to a specific user role. Is this possible with Kirby ?

---

<div class="post-metadata">

**Author:** ![gerardkd](https://avatars.discourse-cdn.com/v4/letter/g/e56c9b/32.png) [@gerardkd](https://forum.getkirby.com/u/gerardkd)\
**Post date:** [October 30, 2016, 1:33pm UTC](https://forum.getkirby.com/t/frontend-authentication-for-specific-user-role/5635/2 "2016-10-30T13:33:02Z")

</div>

Yes. You can use the `hasRole()` method to check if a user that is logged in has a certain role: [https://getkirby.com/docs/cheatsheet/user/has-role](https://getkirby.com/docs/cheatsheet/user/has-role)

```auto

    /* First, check if there's a user at all :) */
    <?php if($user = $site->user()): ?>
        <?php if($user->hasRole('myRole')): ?>
            User has role :)
        <?php else: ?>
            User hasn't the role.
        <?php endif ?>
    <?php endif ?>

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 30, 2016, 2:00pm UTC](https://forum.getkirby.com/t/frontend-authentication-for-specific-user-role/5635/3 "2016-10-30T14:00:28Z")

</div>

If you also want to put a lock on all assets on those pages, check out the [asset firewall cookbook recipe](https://getkirby.com/docs/cookbook/asset-firewall).

---

<div class="post-metadata">

**Author:** ![danielschmid](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/danielschmid/32/349_2.png) [@danielschmid](https://forum.getkirby.com/u/danielschmid)\
**Post date:** [October 30, 2016, 3:14pm UTC](https://forum.getkirby.com/t/frontend-authentication-for-specific-user-role/5635/4 "2016-10-30T15:14:39Z")

</div>

Thanks @gerardkd and @texnixe. It works perfect.

---

<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:54pm UTC](https://forum.getkirby.com/t/frontend-authentication-for-specific-user-role/5635/5 "2025-02-06T16:54:56Z")

</div>

Archived on February 6, 2025, 4:54pm UTC


