# AuthComponent working fine in my controllers but not in my Components

**URL:** <https://discourse.cakephp.org/t/authcomponent-working-fine-in-my-controllers-but-not-in-my-components/2266>\
**Category:** Need Help\
**Created:** [March 21, 2017, 9:48am UTC](https://discourse.cakephp.org/t/authcomponent-working-fine-in-my-controllers-but-not-in-my-components/2266 "2017-03-21T09:48:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinl](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@martinl](https://discourse.cakephp.org/u/martinl)\
**Post date:** [March 21, 2017, 9:48am UTC](https://discourse.cakephp.org/t/authcomponent-working-fine-in-my-controllers-but-not-in-my-components/2266/1 "2017-03-21T09:48:27Z")

</div>

Hi so I have an issue.  
I create an AuthComponent session in my users controller. This works fine. I can access all the Auth methods such as $this-\>Auth-\>user(‘id’) in all my other controllers.

However the issue is that when I try to use the same function $this-\>Auth-\>user(‘id’) in the components that are used by these controllers i get the following error:- Fatal error: Call to a member function user() on a non-object

At the top of the compnents I have the following code:-

> namespace app\Controller\Component;  
> use App\Controller\AppController;  
> use Cake\Controller\Component;  
> use Cake\Controller\Component\AuthComponent;

I must be missing something. Can someone please help me out

---

<div class="post-metadata">

**Author:** ![littleylv](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/littleylv/32/494_2.png) [@littleylv](https://discourse.cakephp.org/u/littleylv)\
**Post date:** [March 22, 2017, 1:22am UTC](https://discourse.cakephp.org/t/authcomponent-working-fine-in-my-controllers-but-not-in-my-components/2266/2 "2017-03-22T01:22:52Z")

</div>

Just add `public $components = ['Auth'];` In your component class.

[Using Other Components in your Component](https://book.cakephp.org/3.0/en/controllers/components.html#using-other-components-in-your-component)
