You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/docs/auth/index.md
-28Lines changed: 0 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,34 +91,6 @@ auth()->dbConnection($db);
91
91
92
92
:::
93
93
94
-
## Auth + Leaf MVC
95
-
96
-
If you are using Leaf MVC, you can set up Leaf Auth to work with your default database connection by heading over to the `public/index.php` file and uncommenting the line that connects to the database:
| Sync Leaf Db with ORM and connect to the database
105
-
| This allows you to use Leaf Db without having
106
-
| to initialize it in your controllers.
107
-
|
108
-
| If you want to use a different connection from those
109
-
| used in your models, you can remove the line below and
110
-
| add your own connection with:
111
-
| db()->connect(...)
112
-
|
113
-
| **Uncomment the line below to use Leaf Db**
114
-
| **You don't need this line to use Leaf Auth**
115
-
*/
116
-
// \Leaf\Database::initDb(); [!code --]
117
-
\Leaf\Database::initDb(); // [!code ++]
118
-
```
119
-
120
-
That's all you need to do. Leaf Auth will automatically connect to your database using the details in your environment file. The auth configuration for your project can be found in the `config/auth.php` file. You can edit this file to change the configuration of Leaf Auth.
121
-
122
94
## Database Considerations
123
95
124
96
Leaf Auth doesn't give you any structure for your database, with that, you can structure your database in any way you prefer. However, there are some things you should note:
Copy file name to clipboardExpand all lines: src/docs/auth/mvc.md
+239Lines changed: 239 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,245 @@ prev: false
5
5
6
6
# Auth in Leaf MVC
7
7
8
+
Leaf Auth comes with everything you need to authenticate users, including login, registration, account verification and more. You can add it to your Leaf MVC project using the Leaf CLI or composer:
9
+
10
+
::: code-group
11
+
12
+
```bash:no-line-numbers [Leaf CLI]
13
+
leaf install auth
14
+
```
15
+
16
+
```bash:no-line-numbers [Composer]
17
+
composer require leafs/auth
18
+
```
19
+
20
+
:::
21
+
22
+
Leaf Auth will automatically pick up your default database connection and will work with it, so you can immediately start working with it without any config. Checkout the following pages to authenticate users:
23
+
24
+
-[Login](/docs/auth/login)
25
+
-[Register](/docs/auth/register)
26
+
-[User Data](/docs/auth/user)
27
+
-[Protected routes](/docs/auth/protected-routes)
28
+
-[Roles & Permissions](/docs/auth/permissions)
29
+
30
+
## Configuring Auth
31
+
32
+
Although Leaf Auth works out of the box for most applications, you may have some specific requirements that you need to configure. You can configure Leaf Auth using your `.env` file:
33
+
34
+
```txt [.env]
35
+
AUTH_DB_TABLE=users
36
+
AUTH_DB_ID=id
37
+
AUTH_TIMESTAMPS=true
38
+
AUTH_TIMESTAMPS_FORMAT='YYYY-MM-DD HH:mm:ss'
39
+
AUTH_SESSIONS=true
40
+
```
41
+
42
+
These are options for the database table to store users, the primary key of the table, whether to use timestamps and the format of the timestamps, and whether to use sessions. If you need to configure something else, you will need to publish the entire auth config using the MVC CLI:
43
+
44
+
```bash:no-line-numbers
45
+
php leaf config:publish auth
46
+
```
47
+
48
+
This will generate a `config/auth.php` file with the default auth config. You can then edit this file to suit your needs.
'messages.loginPasswordError' => 'Password is incorrect!',
242
+
];
243
+
```
244
+
245
+
While this is quite lengthy, it offers fine-grained control over how Leaf Auth works in your application.
246
+
8
247
## What to read next
9
248
10
249
Now that you have built a simple pre-launch page, the next step is to get you familiar with the basics of building a full-stack application with Leaf. So you can build and launch your next big idea *fast*.
0 commit comments