cakephp / authentication

Authentication plugin for CakePHP. Can also be used in PSR7 based applications.
MIT License
115 stars 101 forks source link

`isLoggedIn()` in a Controller? #619

Closed mehov closed 10 months ago

mehov commented 1 year ago

In a view or a template I can call isLoggedIn():

$this->loadHelper('Authentication.Identity');
debug($this->Identity->isLoggedIn());

But how do I check whether a user is logged in inside a Controller?

I want to load different templates based on if a user is logged in.

mehov commented 1 year ago

The code search is finding only the src/View/Helper/IdentityHelper.php

markstory commented 1 year ago

But how do I check whether a user is logged in inside a Controller?

You can read the current identity from $this->Authentication->getIdentity(), if it isn't null, the user is logged in :smile: