|
1 | 1 | <?php |
2 | 2 |
|
3 | | -namespace App\Controllers\Auth; |
| 3 | +namespace App\Controllers; |
| 4 | + |
| 5 | +// Leaf Auth is a package which makes user authentication simple |
| 6 | +use Leaf\Auth; |
| 7 | +use Leaf\Helpers\Password; |
4 | 8 |
|
5 | 9 | /** |
6 | | - * This is a base controller for the auth namespace |
| 10 | + * This is the base controller for your Leaf API Project. |
| 11 | + * You can initialize packages or define methods here to use |
| 12 | + * them across all your other controllers which extend this one. |
7 | 13 | */ |
8 | | -class Controller extends \App\Controllers\Controller |
| 14 | +class Controller extends \Leaf\ApiController |
9 | 15 | { |
10 | | - // |
| 16 | + /** @var \Leaf\Auth */ |
| 17 | + public $auth; |
| 18 | + |
| 19 | + public function __construct() |
| 20 | + { |
| 21 | + parent::__construct(); |
| 22 | + |
| 23 | + // In this version, request isn't initialised for you. You can use |
| 24 | + // requestData() or request() to get request data or initialise it yourself |
| 25 | + $this->auth = new Auth; |
| 26 | + |
| 27 | + // autoConnect uses the .env variables to quickly connect to db |
| 28 | + $this->auth->autoConnect(); |
| 29 | + |
| 30 | + // set default token expiry time |
| 31 | + $this->auth->tokenLifetime(60 * 60 * 24 * 365); |
| 32 | + |
| 33 | + // You can configure auth to get additional customizations |
| 34 | + // This can be done here with the Auth::config method or |
| 35 | + // simply in the Config/auth.php file |
| 36 | + $this->auth->config(authConfig("settings")); |
| 37 | + |
| 38 | + // You can refer to https://leafphp.netlify.app/#/leaf/v/2.4/core/auth for auth docs |
| 39 | + |
| 40 | + // New in v2.5. This alloows us to direct our attention |
| 41 | + // to session authentication instead of the default API JWT method. |
| 42 | + $this->auth->useSession(); |
| 43 | + } |
11 | 44 | } |
0 commit comments