# Display the data of a logged in user

**URL:** <https://discourse.cakephp.org/t/display-the-data-of-a-logged-in-user/8160>\
**Category:** Need Help\
**Created:** [August 1, 2020, 11:45pm UTC](https://discourse.cakephp.org/t/display-the-data-of-a-logged-in-user/8160 "2020-08-01T23:45:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yvesroma190](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/yvesroma190/32/1926_2.png) [@yvesroma190](https://discourse.cakephp.org/u/yvesroma190)\
**Post date:** [August 1, 2020, 11:45pm UTC](https://discourse.cakephp.org/t/display-the-data-of-a-logged-in-user/8160/1 "2020-08-01T23:45:46Z")

</div>

Hello everyone, I am using cakephp 3.8 and would like to display the name of the logged in user in the default.ctp. How do I go about this because $this-\>request-\>session() -\>read(‘Auth.User.name’) gives no results.  
Thank you all.

---

<div class="post-metadata">

**Author:** ![PeterVARGA](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/petervarga/32/1928_2.png) [@PeterVARGA](https://discourse.cakephp.org/u/PeterVARGA)\
**Post date:** [August 2, 2020, 10:36am UTC](https://discourse.cakephp.org/t/display-the-data-of-a-logged-in-user/8160/2 "2020-08-02T10:36:27Z")

</div>

This is how I do it in CakePHP 4.1:

`$user = $this->request->getAttribute('identity');`

Then, you can access any of the `user` table fields with `$user->FIELDNAME`, for example, `$user->email`

---

<div class="post-metadata">

**Author:** ![ishan](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ishan/32/2589_2.png) [@ishan](https://discourse.cakephp.org/u/ishan)\
**Post date:** [August 2, 2020, 4:39pm UTC](https://discourse.cakephp.org/t/display-the-data-of-a-logged-in-user/8160/3 "2020-08-02T16:39:22Z")

</div>

Hi @yvesroma190,

As you’ve said you’re using CakePHP 3.8, I’m assuming you are using AuthComponent to handle authentication. You can get logged in user’s data via `$this->Auth->user('name');`. It will return only data that you’ve set while [logging user](https://book.cakephp.org/3/en/controllers/components/authentication.html#identifying-users-and-logging-them-in) in `$this->Auth->setUser($user)`.

I suggest you give [https://book.cakephp.org/3/en/controllers/components/authentication.html](https://book.cakephp.org/3/en/controllers/components/authentication.html) link a read from where you can get reference.

---

<div class="post-metadata">

**Author:** ![yvesroma190](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/yvesroma190/32/1926_2.png) [@yvesroma190](https://discourse.cakephp.org/u/yvesroma190)\
**Post date:** [September 13, 2020, 5:11am UTC](https://discourse.cakephp.org/t/display-the-data-of-a-logged-in-user/8160/4 "2020-09-13T05:11:44Z")

</div>

Thank you all for help
