# Auth Config

Auth config allows you to directly configure how Leaf\Auth behaves. Auth is basically used for authentication, so, configuring this file will allow you to make customizations to your app authentication.

<?php

use Leaf\Helpers\Password;

return [
    /*
    |--------------------------------------------------------------------------
    | Database table
    |--------------------------------------------------------------------------
    |
    | This is the table that leaf auth will perform authentication
    | checks on and edit/retrieve users from.
    |
    */
    'DB_TABLE' => 'users',

    /*
    |--------------------------------------------------------------------------
    | Use session
    |--------------------------------------------------------------------------
    |
    | Use session based authentication instead of the default JWT based auth.
    |
    */
    'USE_SESSION' => true,

    /*
    |--------------------------------------------------------------------------
    | Generate timestamps
    |--------------------------------------------------------------------------
    |
    | Automatically generate created_at/updated_at timestamps for register
    | and update methods
    |
    */
    'USE_TIMESTAMPS' => true,

    /*
    |--------------------------------------------------------------------------
    | Encode password
    |--------------------------------------------------------------------------
    |
    | Password encode is run when leaf wants to encode passwords on register
    | This exact method is used by default in Leaf, so you can set it to null
    | if you want to.
    |
    | You can set your own implementation instead of Password::hash
    |
    */
    'PASSWORD_ENCODE' => function ($password) {
        return Password::hash($password);
    },

    /*
    |--------------------------------------------------------------------------
    | Verify Password
    |--------------------------------------------------------------------------
    |
    | This function is run to verify the password. This implementation is done
    | by default, so you can set it to null, and it will still work fine.
    |
    | You can add your own implementation instead of Password::verify
    |
    */
    'PASSWORD_VERIFY' => function ($password, $hashedPassword) {
        return Password::verify($password, $hashedPassword);
    },

    /*
    |--------------------------------------------------------------------------
    | Password Key
    |--------------------------------------------------------------------------
    |
    | The default password key. Leaf will expect this key to hold passwords
    | in your database.
    |
    */
    'PASSWORD_KEY' => 'password',

    /*
    |--------------------------------------------------------------------------
    | Hide id
    |--------------------------------------------------------------------------
    |
    | Hide id field from user object returned in login, register and update
    |
    */
    'HIDE_ID' => true,

    /*
    |--------------------------------------------------------------------------
    | Hide password
    |--------------------------------------------------------------------------
    |
    | Hide password from user object returned in login, register and update
    |
    */
    'HIDE_PASSWORD' => true,

    /*
    |--------------------------------------------------------------------------
    | Login params error
    |--------------------------------------------------------------------------
    |
    | Error to show when the login params aren't found in db
    |
    */
    'LOGIN_PARAMS_ERROR' => 'Username not registered!',

    /*
    |--------------------------------------------------------------------------
    | Password error
    |--------------------------------------------------------------------------
    |
    | Error to show when the login password is wrong
    |
    */
    'LOGIN_PASSWORD_ERROR' => 'Password is incorrect!',

    /*
    |--------------------------------------------------------------------------
    | Session on register
    |--------------------------------------------------------------------------
    |
    | If true, a session will be created on a successful registration, else
    | you it'll be created on login rather.
    |
    */
    'SESSION_ON_REGISTER' => false,

    /*
    |--------------------------------------------------------------------------
    | Login page route
    |--------------------------------------------------------------------------
    */
    'GUARD_LOGIN' => '/auth/login',

    /*
    |--------------------------------------------------------------------------
    | Register page route
    |--------------------------------------------------------------------------
    */
    'GUARD_REGISTER' => '/auth/register',

    /*
    |--------------------------------------------------------------------------
    | Logout route
    |--------------------------------------------------------------------------
    */
    'GUARD_HOME' => '/home',

    /*
    |--------------------------------------------------------------------------
    | Logout route
    |--------------------------------------------------------------------------
    */
    'GUARD_LOGOUT' => '/auth/logout',

    /*
    |--------------------------------------------------------------------------
    | Home page route
    |--------------------------------------------------------------------------
    */
    'GUARD_HOME' => '/home',

    /*
    |--------------------------------------------------------------------------
    | JWT + Session
    |--------------------------------------------------------------------------
    |
    | Add an auth token to the auth session?
    |
    */
    'SAVE_SESSION_JWT' => false,

    /*
    |--------------------------------------------------------------------------
    | JWT Token Secret
    |--------------------------------------------------------------------------
    |
    | Secret string to encode JWT
    |
    */
    'TOKEN_SECRET' => '@_leaf$0Secret!',

    /*
    |--------------------------------------------------------------------------
    | JWT Lifetime
    |--------------------------------------------------------------------------
    |
    | How long should JWT be valid for?
    |
    */
    'TOKEN_LIFETIME' => 60 * 60 * 24 * 365
];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195