How to check if a user logged in? |
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?
you can use filter for that : https://codeigniter4.github.io/CodeIgnit...lters.html
or checkout loni's auth module https://github.com/lonnieezell/myth-auth https://github.com/lonnieezell/ezauth
My approach is with Filters:
PHP Code: //app/Config/Filters.php PHP Code: //app/Filters/Auth.php
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?
Actually I can apply filter directly in the routes.php
PHP Code: $routes->group('api', ['filter' => 'api-auth'], function($routes)
2 Filters Class: Authentication and Authorization
PHP Code: public $globals = [ |
Welcome Guest, Not a member yet? Register Sign In |