# $user not available

**URL:** https://forum.getkirby.com/t/user-not-available/9516
**Category:** Questions
**Tags:** v2
**Created:** [January 21, 2018, 8:56pm UTC](https://forum.getkirby.com/t/user-not-available/9516 "2018-01-21T20:56:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)
#### Post date: [January 21, 2018, 8:56pm UTC](https://forum.getkirby.com/t/user-not-available/9516/1 "2018-01-21T20:56:21Z")

</div>

I have built a site with user authentication, following this tutorial from the cookbook

[https://getkirby.com/docs/cookbook/authentication](https://getkirby.com/docs/cookbook/authentication)

Login of registered users works.

Now, I want to show the username of the logged in user in the menu bar, using code like this in my templates:

```
<?php echo ($user->username()) ?>

```

Always get an error: Undefined variable: User

Kind of perplexed, should definitely work.

Any hint?

---

<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: [January 21, 2018, 9:00pm UTC](https://forum.getkirby.com/t/user-not-available/9516/2 "2018-01-21T21:00:00Z")

</div>

No, this won’t work if you don’t define your `$user` variable first:

```auto
<?php
if($user = $site->user()) {
  echo $user->username();
}
?>

```

---

<div class="post-metadata">

### Author: ![steenweg](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@steenweg](https://forum.getkirby.com/u/steenweg)
#### Post date: [January 21, 2018, 9:02pm UTC](https://forum.getkirby.com/t/user-not-available/9516/3 "2018-01-21T21:02:49Z")

</div>

textnixe, you´re my life-saver!

Thank yo so much!

Thomas

---

<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, 5:30pm UTC](https://forum.getkirby.com/t/user-not-available/9516/4 "2025-02-06T17:30:12Z")

</div>


