How to check if a user logged in? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: How to check if a user logged in? (/showthread.php?tid=72952) |
How to check if a user logged in? - happyape - 03-05-2019 I can check and restrict access to certain methods or controllers by defining a helper method PHP Code: function checkLoggedIn() { Then an example usage is as below. PHP Code: namespace App\Controllers; Do you have any better method than this helper method? E.g. in laravel there are guards. Could I achieve something similar without having to write too much of code? RE: How to check if a user logged in? - puschie - 03-06-2019 you can use filter for that : https://codeigniter4.github.io/CodeIgniter4/incoming/filters.html or checkout loni's auth module https://github.com/lonnieezell/myth-auth https://github.com/lonnieezell/ezauth RE: How to check if a user logged in? - elephpantech - 03-06-2019 My approach is with Filters: PHP Code: //app/Config/Filters.php PHP Code: //app/Filters/Auth.php RE: How to check if a user logged in? - happyape - 03-07-2019 Thank you for sharing your solution @elephpantech. PHP Code: //app/config/filters.php I think I need to look into services for that purpose perhaps? RE: How to check if a user logged in? - happyape - 03-07-2019 Actually I can apply filter directly in the routes.php PHP Code: $routes->group('api', ['filter' => 'api-auth'], function($routes) RE: How to check if a user logged in? - elephpantech - 03-11-2019 2 Filters Class: Authentication and Authorization PHP Code: public $globals = [ |