Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Nuxt 3 Authentication with Laravel Sanctum:A Practical Guide
Rating: 4.8 out of 5(7 ratings)
65 students

Nuxt 3 Authentication with Laravel Sanctum:A Practical Guide

Learn how to build a full authentication boilerplate with Nuxt, Sanctum and Fortify.
Created byTapan Sharma
Last updated 4/2025
English
English [Auto],

What you'll learn

  • Learn how to Develop a starter kit with Login/Registration features using Laravel Sanctum, Fortify and Nuxt 3 as the frontend stack
  • Learn how to set up a Laravel project with Sanctum and Fortify.
  • Learn how to Implement authentication in Nuxt 3 with a Laravel Backend
  • Learn how to configure and use Laravel Sanctum to communicate with a Single Page Application (SPA)
  • Learn how to Implement Two Factor Authentication (2FA) with Laravel, Fortify and Nuxt
  • Learn how to Implement Roles/Permissions in an API/SPA Environment
  • Learn how to Use API Resources in Laravel to format the data accordingly
  • Learn how to Implement Middlewares like Authenticated and Guest Middlewares to protect pages accordingly
  • Learn how to Build a mini Students Management System from Scratch
  • We'll also learn how to implement Server Driven Paginations, Search Functionality along with Filter By Class.

Course content

5 sections • 39 lectures • 6h 44m total length
  • Client and API Project Setup4:56

    Install fresh backend and frontend projects in a single Nuxt Laravel folder, setting up a Laravel backend with SQLite and a Nuxt frontend via npm.

  • Using the Same Domain2:49

    Configure Nuxt to serve frontend and backend on the same domain using backend.test, adjust dev server settings, and restart npm to enable domain-shared hosting for future Sanctum session-based authentication.

  • Laravel Sanctum Configuration9:08

    Configure Laravel Sanctum to enable cookie-based, stateful authentication between front end and back end for a single page application, and adjust env, cors, and session settings.

  • Install Nuxt-Auth-Sanctum Package2:55

    Install and configure the Nuxt auth sanctum module to enable cookie-based, SSR-ready Laravel Sanctum authentication, using a sanctum composable, CSRF handling, and pre-configured middlewares like auth and guest.

  • Making our First Request13:22

    Test the Laravel Sanctum configuration by making a login request from a Nuxt 3 app, register pages, and verify authentication flow with a backend route.

  • Structuring Our Nuxt App10:18

    Install tailwind CSS and set up a default layout to structure the Nuxt app with a dashboard and Nuxt link navigation. Prepare for Laravel Fortify authentication in the next lecture.

  • Authenticating with Fortify7:07

    Install and configure Laravel Fortify to implement login plus registration, password resets, and email verification with optional two-factor authentication in a Nuxt Laravel project.

  • Fetching the Authenticated User6:16

    Grab the authenticated user from the use sanctum auth composable and render their name in navigation, while refining the login and nav design.

  • Using API Resource and Interface for the User10:51

    Learn how to use Laravel API resources to format front-end data, including nested user and post relationships, wrapping behavior, and disabling the data key, plus defining a TypeScript user interface.

  • Using TS interface for Login Form2:47

    Define a TypeScript interface for the login form with email and password, wire it into the login view for autocomplete, and note middlewares like auth and guest.

  • Protecting pages with the Guest and Auth Middlewares8:41

    Protect pages with Sanctum auth and Sanctum guest middlewares, redirecting unauthenticated users to login and authenticated users away from guest pages. Configure titles with define page meta and use head.

  • Signing Out5:52

    Implement and test logout with the Nuxt sanctum auth composable, wiring a logout button to an async action, include the logout route, and use on logout redirect for post-sign-out navigation.

  • Registering an Account12:14

    Implement a Nuxt frontend registration flow with Laravel Fortify and Sanctum, building a register page with name, email, password, and confirmation and posting to /register.

  • Moving over to a composable6:44

    Move registration logic from the user interface to a dedicated composable named use auth, using sanctum and refresh identity to update authentication status and render the dashboard.

  • Displaying Validation Errors8:26

    Render server-driven validations in a Nuxt 3 app by handling 422 responses during user registration, displaying field-specific errors (name, email, password) and applying conditional styling to highlight invalid inputs.

  • Updating Profile Details10:54

    Implement a profile update flow by adapting the registration form into a profile form for name and email, using sanctum auth and refresh identity to reflect changes.

Requirements

  • Beginner Level knowledge of PHP/Laravel is required
  • Beginner Level knowledge of Nuxt and VueJS is required

Description

Unlock the power of full-stack development with our step-by-step guide to authenticating with a Laravel API from a Nuxt front-end. This course is designed to take you from the basics to advanced features, ensuring you understand how to secure your applications effectively.


This course covers everything you need to get started with authentication with Nuxt and Laravel. We’ll start by setting up a Nuxt project and configuring Laravel Sanctum, then add the ability to register, sign in, and sign out.

We’ll also cover some TypeScript tips, protecting pages with middleware, and using Vue composables to keep our code tidy.


Projects Roadmap and Status:

[Uploaded] Setting Up Laravel and Nuxt

[Uploaded] A Guide to Implement Two Factor Authentication (2FA) with Laravel and Nuxt

[Uploaded] Let's Build a Student Management System

[Uploaded] A Guide to Implement Roles/Permissions in an API/SPA Environment

[Uploaded] Miscellaneous Issues and Fixes


Project Description:


Building an Authentication System

We'll start by setting up a fresh Laravel project with Sanctum and Fortify, configuring everything step-by-step, and then we'll implement the ability to authenticate from Nuxt with the nuxt-auth-sanctum module.


Section Highlights:

  • Set up a fresh Laravel project with Sanctum and Fortify.

  • Learn how to properly configure Laravel Sanctum to be able to communicate with a front-end SPA easily

  • Learn how to properly configure a Nuxt frontend (along with Nuxt-Auth-Sanctum) to communicate with a Laravel Backend.

  • Configure and implement authentication using the Nuxt-Auth-Sanctum module.

  • Build a simple yet effective authentication module.

  • Create a simple yet beautiful starter kit with authentication features like Login, and Registration.

  • Learn how to implement middlewares like Authenticated and Guest Middlewares to protect pages Accordingly

  • Learn how to use API Resources in Laravel to format the data accordingly


A Guide to Implement Two Factor Authentication (2FA) with Laravel and Nuxt

In this section, we'll explore how to implement Two Factor Authentication (2FA) with Laravel and Nuxt. We'll use the Laravel Fortify package to handle the 2FA logic, and then we'll integrate it with the Nuxt-Auth-Sanctum module.


Section Highlights:

  • We'll learn how to Enable and Disable 2FA with Laravel Fortify.

  • We'll also implement the Password Confirmation flow so that users have to confirm their password before enabling/disabling 2FA.

  • And finally, we'll show the two-factor challenge when the user tries to log in, this will only be shown if 2FA is enabled.


Let's Build a Student Management System

In this section, we'll build a simple CRUD app and dive into the fundamentals of building CRUD applications with Laravel, Sanctum, and Nuxt 3, we will learn the following topics along the way:


  • Learn about Watchers in Vue.js and Build dependent dropdowns.

  • Learn how to work with Factories and Seeders in Laravel, and seed the necessary data for all of our Models

  • Learn how to Implement Server Side Pagination from scratch.

  • Learn how to Implement Search Functionality from scratch, this includes multi-column search.

  • Learn how to Implement Filter By Class Functionality from scratch.

  • Learn how to display server-driven validation errors.

  • And many more.


A Guide to Implement Roles/Permissions in an API/SPA Environment

In this section, we'll learn how to implement Roles/Permissions in an API/SPA Environment.


  • We'll start with the backend first by implementing the necessary models/migrations and seeders.

  • Then we'll implement authorization checks on both the frontend and backend to ensure that only authorized users can access certain resources.


Miscellaneous Issues and Fixes In this section, we'll cover some miscellaneous issues and fixes that you might encounter while building your application.

  • We'll learn how to fix the login issue that occurred when we implemented 2FA.

  • We'll also learn how to replace the history when logging in.



Whether you're a beginner looking to get started with API authentication or an experienced developer wanting to refine your skills, this course has something for you. Join us and enhance your development toolkit today!

Who this course is for:

  • Students who want to Integrate Laravel as a Backend with a Nuxt Frontend