# Check current user Auth ID in view

**URL:** <https://discourse.cakephp.org/t/check-current-user-auth-id-in-view/9745>\
**Category:** Need Help\
**Tags:** help\
**Created:** [September 27, 2021, 4:28pm UTC](https://discourse.cakephp.org/t/check-current-user-auth-id-in-view/9745 "2021-09-27T16:28:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![20cents](https://avatars.discourse-cdn.com/v4/letter/2/58956e/32.png) [@20cents](https://discourse.cakephp.org/u/20cents)\
**Post date:** [September 27, 2021, 4:28pm UTC](https://discourse.cakephp.org/t/check-current-user-auth-id-in-view/9745/1 "2021-09-27T16:28:42Z")

</div>

Hi all,

Can you please let me know if the below is the proper way to list all users except the one currently logged in the view ?

```auto
<?php //Listing all users
                            foreach($users as $user) :
                                if($user->id != $this->request->getSession()->read('Auth')->id):
                                ?>
                                    <tr>
                                        <td class="align-middle"><?= $user->firstname ?></td>
                                        <td class="align-middle"><?= $user->lastname ?></td>
                                        <td class="align-middle"><?= $user->email ?></td>
                                        <td class="align-middle"><?= $user->role ?></td>
                                        <td class="align-middle"><?= $user->created->format('d/m/Y') ?></td>
                                        <td class="align-middle">
                                            <?= $this->Html->link('<i class="far fa-trash-alt"></i>', ['action' => 'delete', $user->id], ['class' => 'btn btn-danger', 'escape' => false]) ?>
                                        </td>
                                    </tr>
                                <?php endif; ?>
                            <?php endforeach; ?>

```

---

<div class="post-metadata">

**Author:** ![dirk](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dirk/32/2174_2.png) [@dirk](https://discourse.cakephp.org/u/dirk)\
**Post date:** [September 27, 2021, 5:40pm UTC](https://discourse.cakephp.org/t/check-current-user-auth-id-in-view/9745/2 "2021-09-27T17:40:16Z")

</div>

You should do the selection in the controller, not in the view

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 27, 2021, 11:05pm UTC](https://discourse.cakephp.org/t/check-current-user-auth-id-in-view/9745/3 "2021-09-27T23:05:47Z")

</div>

Also, the “proper” way will depend on what version of CakePHP you’re running, and whether you’re using the new authentication plugin or the old component.
