Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@qirolab/nuxt-sanctum-authentication

qirolab844MIT0.1.15TypeScript support: included

Nuxt 3 module for easy Laravel Sanctum authentication, offering CSRF token management, both cookie and token-based auth, and SSR compatibility.

auth, laravel, sanctum, sanctum-authentication, laravel-sanctum-auth, nuxt-auth, authentication, token-based-auth, cookie-based-auth

readme

Nuxt Sanctum Authentication

npm version npm downloads License Nuxt

Introduction

The nuxt-sanctum-authentication module seamlessly integrates Laravel Sanctum with Nuxt 3 to provide a simple and secure authentication process for your application. It works efficiently in both Server-Side Rendering (SSR) and Client-Side Rendering (CSR) environments, ensuring consistent and reliable authentication regardless of how your app is rendered.

Key features

  • Seamless CSR and SSR Support: Works smoothly in both client-side and server-side rendering modes.
  • Automatic CSRF Token Management: Automatically handles CSRF tokens to protect your app from cross-site request forgery attacks.
  • Bearer Token Management: Manages Bearer tokens for secure access to protected resources.
  • Integration with Nuxt's ofetch Client: Fully compatible with Nuxt's ofetch client for making authenticated HTTP requests in your application.

Important: Before using this module, make sure that Laravel Sanctum is correctly configured on your backend. For more detailed setup instructions, refer to the Laravel Sanctum documentation.

Documentation

For full documentation, including setup instructions and API reference, visit the Nuxt Sanctum Authentication Documentation.

Video Tutorial

Watch the step-by-step guide on how to use the nuxt-sanctum-authentication module in this Video Tutorial.

Demo Repository

To explore the source code, check out the Nuxt Sanctum Authentication Demo Repository.

  • For Cookie-Based SPA Authentication, see the main branch.
  • For API Token Authentication, check out the api-token-authentication branch.

Contributing

Contributions to the nuxt-sanctum-authentication module are welcome! Whether it's bug fixes, feature enhancements, or documentation improvements, feel free to submit a pull request.

Development Setup

  1. Fork the repository.
  2. Clone your forked repository.
  3. Install dependencies: npm install or yarn install.
  4. Make your changes and commit them with a clear and descriptive message.
  5. Push your changes to your forked repository.
  6. Submit a pull request.

Support my work

If you found this demo helpful and want to support my work, check out some of my other products:

Ctrl+Alt+Cheat     Spec Coder     JavaScript Guide

DigitalOcean Referral Badge


License

The nuxt-sanctum-authentication module is open-source software licensed under the MIT license.

changelog

Changelog

All notable changes to the "spec-coder" extension will be documented in this file.

Check Keep a Changelog for recommendations on how to structure this file.

v0.1.15

compare changes

🚀 Enhancements

  • Add generic login response type (1235bda)
  • Add example code for login callback (9abfa83)

❤️ Contributors

v0.1.14

compare changes

🚀 Enhancements

  • Add provider option to ModuleOptions (ce5198e)
  • Add client options to useSanctum login (48ddc12)
  • Improve type safety in useSanctumFetch (5ca2ade)

🩹 Fixes

  • Handle MaybeArray for onRequest and onResponseError hooks (6f174a6)
  • Make submit options optional in SanctumForm (57c6066)
  • Ensure options defaults to FetchOptions type (29a4b3f)

📖 Documentation

  • Add link to nuxt-sanctum-authentication module (adfeb90)

❤️ Contributors

v0.1.13

compare changes

🩹 Fixes

  • Remove unnecessary try/catch block (fddde74)
  • Handle token extraction error silently (79ff2ab)
  • Log error when fetching authenticated user (7f05734)

❤️ Contributors

v0.1.12

compare changes

🚀 Enhancements

  • Add extractNestedValue utility (c46eb2d)
  • Add getAuthUser helper (85525f7)
  • Add configurable token response key and logging (3d650bf)
  • Add responseKey option to SanctumModule (40d6115)
  • Add userResponseWrapperKey to ModuleOptions (4821f23)
  • Add fetchService and logger to getAuthUser (ccfbceb)
  • Use getAuthUser to fetch user data (fdbf3a5)
  • Add HasApiTokens trait to user model (15afb7c)
  • Add token authentication (15e51c2)
  • Add token authentication routes (e2f55da)

🩹 Fixes

  • Allow null token value (9783aaf)
  • Use getAuthUser function to fetch user (2016d7e)
  • Update sanctum endpoints (187fd3f)

🎨 Styles

  • Set $wrap to 'data' in UserResource (1793c98)

❤️ Contributors

v0.1.11

compare changes

🚀 Enhancements

  • Update profile form to patch request (6bbd206)
  • Add onRequestError callback to useSanctumForm (ac396a6)

🩹 Fixes

  • Update profile route to PATCH (2a9ddad)

🎨 Styles

  • Ignore laravel-api fixtures in lint:fix (2e090ca)

❤️ Contributors

v0.1.10

compare changes

🚀 Enhancements

  • Add object-to-formdata helper (1e2bcf4)
  • Add SanctumForm interface (5a963b6)
  • Add objectToFormData helper to useSanctumForm (a2b0197)

🩹 Fixes

  • Remove object-to-formdata dependency (c966a9b)
  • Make ModuleOptions properties required (72bd80d)
  • Remove unnecessary cast (27c9066)

🏡 Chore

❤️ Contributors

v0.1.9

compare changes

🚀 Enhancements

  • Add object-to-formdata dependency (8709c5e)

❤️ Contributors

v0.1.8

compare changes

🩹 Fixes

  • Update object-to-formdata dependency (3daee5f)

❤️ Contributors

v0.1.7

compare changes

🚀 Enhancements

  • Add lodash-es and object-to-formdata dependencies (d7ff803)
  • Add custom onRequest and onResponseError hooks (7fc1cf6)
  • Replace $sanctumFetch with a custom fetch service (8f3731f)
  • Add hasFile helper (ba45fd2)
  • Add form type (0bf4cf7)
  • Create useSanctumForm composable (fad10c9)
  • Profile page form improvements (17da722)
  • Extract onRequest and onResponseError from options (bf258a5)
  • Add reset method to form (bb2b188)
  • Add reset method to useSanctumForm (330b59c)
  • Add form validation and reset button (56f8464)
  • Refactor useSanctumForm composable (264260f)
  • Add form API (213f354)
  • Add avatar to profile page (4bb00bf)
  • Add avatar to User model (600dafc)
  • Add avatar to user resource (463edca)

🩹 Fixes

  • Add empty object as first argument to createFetchService (703b7e2)
  • Change errors type to array (9c4d8fe)
  • Convert validation errors to array (342c1df)
  • Change errors type to string (19afa1b)
  • UseSanctumForm: simplify validation errors (fb71944)
  • Fix border-danger style (d91eaee)
  • Update host and apiUrl to localhost (5a65216)
  • Store avatar in public disk (86955e1)
  • Ignore test fixtures in lint command (3fd73e6)

💅 Refactors

  • Remove user preview and change label name (48a1f9b)

📖 Documentation

🏡 Chore

🎨 Styles

  • Enable prettier-vscode as default formatter (08159bb)
  • Remove arrow-parens rule (89785cf)

❤️ Contributors

v0.1.6

compare changes

📖 Documentation

  • Add video tutorial and demo repository (93fba0f)

❤️ Contributors

v0.1.5

compare changes

💅 Refactors

❤️ Contributors

v0.1.4

compare changes

v0.1.3

compare changes

💅 Refactors

🏡 Chore

❤️ Contributors

v0.1.2

compare changes

🚀 Enhancements

🩹 Fixes

  • Add type annotation to fetchService (86bfb28)
  • Update module name and package name (f4b7ad7)

💅 Refactors

  • Remove version from module meta (1cbcc69)

❤️ Contributors

v0.1.0

  • Initial release
  • Automated CSRF token management
  • Bearer token management
  • Supports both CSR and SSR
  • Compatible with Nuxt's ofetch client
  • useSanctumAuth composable
  • Authentication:
    • Login
    • Logout
    • Get current user
    • Refresh User