Skip to content

Commit d762091

Browse files
committed
✨ Integrated scaffolding
1 parent 4328d23 commit d762091

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

App/Controllers/Controller.php

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
11
<?php
22

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;
48

59
/**
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.
713
*/
8-
class Controller extends \App\Controllers\Controller
14+
class Controller extends \Leaf\ApiController
915
{
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+
}
1144
}

0 commit comments

Comments
 (0)