Skip to content

jjjrmy/nuxt-auth-sanctum

 
 

Repository files navigation

Nuxt Auth Sanctum

npm version npm downloads License Nuxt

This module provides a simple way to use Laravel Sanctum with Nuxt by leveraging cookies-based authentication. SSR-ready!

Features

  • useSanctumAuth composable for easy access to the current user and authentication methods
  • Automated CSRF token header and cookie management
  • Both CSR and SSR modes support
  • Pre-configured middleware for pages that require authentication
  • Cast current user information to any class you want
  • Compatible with default Nuxt ofetch client
  • TypeScript support

Note: Before using this module, please make sure that you have already configured Laravel Sanctum on your backend. You can find more information about Laravel Sanctum here.

Complete documentation - Nuxt Auth Sanctum docs.

Quick Setup

  1. Add nuxt-auth-sanctum dependency to your project
# Using pnpm
pnpm add -D nuxt-auth-sanctum

# Using yarn
yarn add --dev nuxt-auth-sanctum

# Using npm
npm install --save-dev nuxt-auth-sanctum
  1. Add nuxt-auth-sanctum to the modules section of nuxt.config.ts
export default defineNuxtConfig({
    modules: ['nuxt-auth-sanctum'],

    // nuxt-auth-sanctum options (also configurable via environment variables)
    sanctum: {
        baseUrl: 'http://localhost:80', // Laravel API
        origin: 'http://localhost:3000', // Nuxt app, by default will be used 'useRequestURL().origin'
    },
});

That's it! You can now use Nuxt Auth Sanctum in your Nuxt app ✨

For more details, check the documentation here.

Development

# Install dependencies
yarn install

# Generate type stubs
yarn dev:prepare

# Develop with the playground
yarn dev

# Build the playground
yarn dev:build

# Run Prettier
yarn fmt

# Run ESLint
yarn lint

# Run Nuxt type check
yarn types

# Run Vitest
yarn test
yarn test:watch

# Release new version
yarn release

About

Nuxt module for Laravel Sanctum authentication

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 80.9%
  • Vue 19.1%