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
@@ -13,6 +13,12 @@ Now you can finally enjoy the auth setup (`register`, `login`, `forgot`, and `re
13
13
14
14
Migrate the `users`, `password_resets` table (they already exist into a fresh Laravel app).
15
15
16
+
<alerttype="success">
17
+
18
+
Laravel 10 automatically ships with Sanctum, so you don't have to install it.
19
+
20
+
</alert>
21
+
16
22
### Install sanctum
17
23
18
24
See the docs [here](https://laravel.com/docs/sanctum#installation). You don't need to add `\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,` in your `'api'` middleware group.
@@ -42,7 +48,8 @@ The `User` model should extend the `Illuminate\Foundation\Auth\User` class or im
42
48
43
49
<alerttype="info">
44
50
45
-
Make sure you didn't skip adding the `\Laravel\Sanctum\HasApiTokens` trait to your `User` model.
51
+
Make sure you have the `\Laravel\Sanctum\HasApiTokens` trait to your `User` model.
52
+
Laravel 10 will automatically add this trait to your `User` model.
46
53
47
54
</alert>
48
55
@@ -66,32 +73,33 @@ Restify provides you a simple way to add all of your auth routes prepared. Simpl
66
73
Route::restifyAuth();
67
74
```
68
75
69
-
And voila, now you have auth routes ready to be used.
76
+
And voilà, now you have auth routes ready to be used.
The `register` and `login` routes are outside the base `restify` prefix because they don't have to follow the `auth` middleware defined in the `config/restify.php` config file.
84
91
85
92
</alert>
86
93
87
-
## Export auth controllers
88
94
89
-
All of these routes are handled by default, so you can just use them facilely. However, you can customize each of them by exporting auth controllers:
95
+
You can also pass an `actions` argument, which is an array of actions you want to register. For example:
Now you have all the auth controllers and blade email files exported into your project.
100
+
101
+
By using the `actions` argument, only the specified routes will be registered. If no `actions` argument is passed, Restify will register all the routes by default.
102
+
95
103
96
104
## Sanctum Middleware
97
105
@@ -105,3 +113,256 @@ Next, add the `auth:sanctum` middleware after the `api` middleware in your confi
105
113
...
106
114
],
107
115
```
116
+
117
+
## Login
118
+
119
+
Let's ensure the authentication is working correctly. Create a user in the DatabaseSeeder class:
After making a POST request to this endpoint, an email will be sent to the provided email address containing a link to reset the password. The link looks like this:
This configuration can be found in the `config/restify.php` file. The FRONTEND_APP_URL should be set to the URL of your frontend app, where the user lands when they click the action button in the email. The "token" is a variable that will be used to reset the password later on.
242
+
243
+
To view the email content during development, you can change the following configuration in your .env file:
244
+
245
+
```dotenv
246
+
MAIL_MAILER=log
247
+
```
248
+
249
+
This will log the email content to the `laravel.log` file, allowing you to see the password reset email without actually sending it.
250
+
251
+
Now, you can send a POST request with Curl:
252
+
253
+
```shell
254
+
curl -X POST "http://restify-app.test/api/forgotPassword" \
If the password reset is successful, you should receive a response similar to the following:
304
+
305
+
```json
306
+
{
307
+
"message": "Your password has been successfully reset."
308
+
}
309
+
```
310
+
311
+
Now the user's password has been successfully reset, and they can log in with their new password.
312
+
313
+
314
+
## Customizing Authentication Controllers
315
+
316
+
You can publish the authentication controllers from the Restify package to your own application, allowing you to customize their behavior as needed. To publish the controllers, run the following command:
317
+
318
+
```shell
319
+
php artisan restify:auth
320
+
```
321
+
322
+
This command will copy the authentication controllers to the `app/Http/Controllers/Restify` directory in your Laravel project.
323
+
324
+
The command accepts an optional `--actions` parameter, which allows you to specify which controllers you want to publish. If no action is passed, the command will publish all controllers and the `ForgotPasswordNotification`. For example, to publish only the `login` and `register` controllers, run:
325
+
326
+
```shell
327
+
php artisan restify:auth --actions=login,register
328
+
```
329
+
330
+
Now, you can make any necessary changes to these controllers to fit your specific requirements.
331
+
332
+
### Customizing the Register Route
333
+
334
+
In a real-world scenario, you might need to customize only the register route. To do this, you can use the `restify:auth` command with the `--actions` option to publish only the register controller:
335
+
336
+
```shell
337
+
php artisan restify:auth --actions=register
338
+
```
339
+
340
+
After running the command, the register controller will be published to your application, and you can modify it to fit your requirements.
341
+
342
+
<alerttype="warning">
343
+
344
+
Important Note: If you want to publish other actions in the future, you'll need to manually update the `routes/api.php` file before running the restify:auth command again. Remove any previously published Restify routes, and keep the `Route::restifyAuth();` line so that the new routes can be correctly published.
345
+
346
+
</alert>
347
+
348
+
For example, if you previously published the register route, your `routes/api.php` file might look like this:
Copy file name to clipboardExpand all lines: docs-v2/content/en/index.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,12 @@ Laravel Restify is an extraordinary tool inspired by [Laravel Nova](https://nova
9
9
10
10
If you don't have an application written with Nova, you can start with Laravel Restify from scratch and get a powerful API in a few minutes.
11
11
12
+
<alerttype="warning">
13
+
14
+
This documentation is for the latest version of Laravel Restify. Please ensure you are using the most recent release of the package to guarantee compatibility with the information provided in this documentation. To update Laravel Restify, refer to the upgrade guide for instructions.
15
+
16
+
</alert>
17
+
12
18
## Features
13
19
14
20
<list :items="[
@@ -22,6 +28,8 @@ If you don't have an application written with Nova, you can start with Laravel R
22
28
]">
23
29
</list>
24
30
31
+
32
+
25
33
## Playground
26
34
27
35
You can find a playground in the [Restify Demo GitHub repository](https://github.com/BinarCode/restify-demo).
0 commit comments