Skip to content

Commit 3185cac

Browse files
committed
feat: update auth docs
1 parent dce438c commit 3185cac

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

.vitepress/config/sidebar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const sidebar = [
103103
text: 'Protecting your routes',
104104
link: '/docs/auth/protected-routes',
105105
},
106-
{ text: 'Updating logged-in user', link: '/docs/auth/update' },
106+
// { text: 'Updating logged-in user', link: '/docs/auth/update' },
107107
{ text: 'Build your own auth library', link: '/docs/auth/helpers' },
108108
],
109109
},

src/docs/auth/login.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,38 @@ auth()->config('session.lifetime', 0); // never expire
194194

195195
:::
196196

197+
## Updating a logged-in user
198+
199+
Updating user information means allowing users to change their details (like username, email, or password) in your application. It is a very common feature in most applications.
200+
201+
Leaf provides an `update()` method that allows you to update a user's information.
202+
203+
```php
204+
$user = auth()->update($data);
205+
```
206+
207+
### Unique values
208+
209+
Leaf Auth allows you to set unique fields which should not be repeated for different users. For example, you wouldn't want two users to have the same email address. You can configure Leaf Auth to check for unique fields when a user is being updated:
210+
211+
```php:no-line-numbers
212+
auth()->config('unique', ['email', 'username']);
213+
```
214+
215+
Now if a user tries to update their profile with an email or username that already exists in the database, Leaf Auth will return an error. You can get the error message using the `errors()` method.
216+
217+
```php
218+
$data = auth()->update([
219+
'username' => 'example',
220+
'email' => '[email protected]'
221+
]);
222+
223+
if(!$data) {
224+
$error = auth()->errors();
225+
// ['email' => 'The email already exists']
226+
}
227+
```
228+
197229
## Signing a user out
198230

199231
When a user chooses to end their session, or their session expires, you can sign them out using the `logout()` method. This method will end the user's session or delete their token.

src/docs/auth/update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# User Update
1+

0 commit comments

Comments
 (0)