Laravel 12 - Jetstream Authentication

Touseef Afridi
02 Apr 25

Laravel 12 - Jetstream Authentication

In this tutorial, we are going to learn how to set up Laravel 12 Jetstream authentication using Livewire or Inertia. Follow a step-by-step guide to implement user login, registration, and two-factor authentication in Laravel 12.

Quick Overview

This guide covers setting up a new Laravel project and integrating authentication using Laravel Jetstream. You'll start by creating a fresh Laravel project, configuring the database, and installing Jetstream. After selecting Livewire or Inertia, you'll generate authentication scaffolding, including login, registration, password reset, and email verification. Next, you'll run database migrations to set up the required tables. Finally, you'll launch the Laravel development server, test registration and login, and confirm the authentication system is fully functional. By the end, you'll have a complete authentication setup, ready for customization and further enhancements.

Step # 1 : Set Up a New Laravel Project.

Note : If Laravel is not installed globally, you need to install it first. Assuming Composer is already set up, run the following command
composer global require laravel/installer
Once installed, create a fresh Laravel project using the global Laravel installer.
laravel new jetstream
During the setup, you'll encounter the following prompts.
  • Which starter kit would you like to install? → Choose None
  • Which database will your application use? → Select MySQL
  • Default database updated. Would you like to run the default database migrations? → Enter No
  • Would you like to run npm install and npm run build? → Enter No

After completing these steps, a new Laravel project named jetstream will be created with the default structure. No starter kit will be included, MySQL will be set as the database without running migrations, and npm dependencies won’t be installed. This results in a clean and minimal setup, ready for customization.

Step # 2 : Navigate to the Project.

Open a terminal (Git Bash, Command Prompt, or any terminal of your choice) and navigate to the root directory of your Laravel project.
cd c:xampp/htdocs/jetstream
Once inside the project folder, you can run commands to start the server, install dependencies, or modify configurations as needed.

Step # 3 : Install the Laravel Jetstream Package.

To install Laravel Jetstream in your project, run the following Composer command.
composer require laravel/jetstream
This will install Laravel Jetstream, an authentication scaffolding package that offers features like login, registration, and email verification. However, the scaffolding is not applied automatically and must be set up in the next step to enable authentication views and routes.

Step # 4 : Configure Laravel Jetstream.

After successfully installing Laravel Jetstream, the next step is to configure its authentication scaffolding. This will enable the necessary features for user authentication. Depending on your preferred stack (Livewire or Inertia), run one of the following commands.
For Livewire :
php artisan jetstream:install livewire
For Inertia (Vue) :
php artisan jetstream:install inertia
During the setup, you may be prompted with the following question.
  New database migrations were added. Would you like to re-run your migrations?
(yes/no) [yes]
Type no as we will be executing the migrations in the next step.
This command will configure essential authentication features for your Laravel project, such as user login, registration, password resets, email verification, and profile management. It will also generate the necessary views and routes to make the authentication system fully functional. At this point, the authentication scaffolding is in place, but the next step will finalize the database setup and ensure everything is ready for use.

Step # 5 : Execute Database Migrations.

To set up the required database tables, run the following command.
php artisan migrate
If the database does not exist, you may encounter the following warning.
WARN The database 'Jetstream' does not exist on the 'mysql' connection.
Would you like to create it? → Type Yes
Type yes to create the database and proceed with the migrations. This will generate the necessary tables for Laravel Jetstream’s authentication system, including user accounts, sessions, password resets, and profile management. It ensures that your application is fully prepared to handle authentication and other Jetstream related features.

Step # 6 : Let's see it in Action.

With everything set up, it’s time to start the Laravel development server. Run the following command in your terminal.
php artisan serve
Once the server is running, head to 127.0.0.1:8000 in your browser to see the homepage of your Laravel application. If everything is configured correctly, you should see the default Laravel welcome page.

Now, let's test the registration process. You can either navigate directly to the register page or click the Register button on the homepage. This will take you to the registration form, where you can enter your information such as name, email, and password, and submit it.

Upon submitting the registration form, the system will process your details, create your user account, and redirect you to the dashboard. This confirms that your registration was successful and that the authentication system is working correctly. The dashboard is the secure area where authenticated users can access their account information and other protected features.


Next, let’s verify the login functionality. You can either visit the login URL manually or click on the Login button on the homepage. This will open the login form, where you can enter the credentials you used during registration.

Enter the credentials you registered with, and after successfully logging in, you will be redirected back to the dashboard. This verifies that the login process is functioning as expected, and the system is properly authenticating your credentials. If everything goes smoothly, you’ll see the dashboard again, confirming the authentication is fully operational.

Now, both the registration and login flows have been successfully tested, confirming that the Jetstream authentication system is working as expected. You now have a fully functional authentication setup that can be customized or extended to meet your specific project needs.

Conclusion

By following this guide, you have successfully set up a fresh Laravel project with authentication using Laravel Jetstream. You configured the database, installed Jetstream, and generated the necessary authentication scaffolding with Livewire or Inertia. After running the migrations, you tested both the registration and login functionalities to ensure everything works correctly. With the authentication system in place, you now have a solid foundation to further customize your application, integrate additional features, or extend the user experience as needed. Laravel's powerful features and ease of use make it a great choice for building scalable applications, from small projects to large enterprise solutions.
For more details, refer to the official Jetstream documentation.
Share this with friends!


"Give this post some love and slap that 💖 button as if it owes you money! 💸😄"
0

0 Comments

To engage in commentary, kindly proceed by logging in or registering