### Install Nuxt Module with npx Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.4_getting-started_installation.md Installs the nuxt-auth-sanctum module using npx and automatically registers it in nuxt.config.ts. This is the recommended method for quick setup. ```bash npx nuxi@latest module add nuxt-auth-sanctum ``` -------------------------------- ### Install Nuxt Module with npx Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.6_getting-started_installation.md Installs the nuxt-auth-sanctum module using npx and automatically registers it in your nuxt.config.ts modules section. This is the recommended method for quick setup. ```bash npx nuxi@latest module add nuxt-auth-sanctum ``` -------------------------------- ### Install Nuxt Auth Sanctum Module with npx Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.3_getting-started_installation.md Installs the nuxt-auth-sanctum module using npx. This command automatically registers the module in your nuxt.config.ts file, simplifying the setup process. ```bash npx nuxi@latest module add nuxt-auth-sanctum ``` -------------------------------- ### Manually Install Nuxt Auth Sanctum Package Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.2_getting-started_installation.md Installs the `nuxt-auth-sanctum` package as a development dependency using common package managers like pnpm, yarn, or npm. ```shell # 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 ``` -------------------------------- ### Install Nuxt Module with Nuxt CLI Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.5_getting-started_installation.md Installs the `nuxt-auth-sanctum` module using the Nuxt CLI. This command automatically registers the module in `nuxt.config.ts` for immediate use. ```bash npx nuxi@latest module add nuxt-auth-sanctum ``` -------------------------------- ### Install Nuxt Auth Sanctum Module with Nuxi Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.2_getting-started_installation.md Installs the `nuxt-auth-sanctum` module using the `nuxi` command-line interface. This command automatically registers the module in your Nuxt project's configuration. ```shell npx nuxi@latest module add nuxt-auth-sanctum ``` -------------------------------- ### Install Nuxt Auth Sanctum Module via npx Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_getting-started_installation.md Installs the nuxt-auth-sanctum module using npx. This command automatically registers the module in your nuxt.config.ts file. ```bash npx nuxi@latest module add nuxt-auth-sanctum ``` -------------------------------- ### Manually Install Nuxt Auth Sanctum Package Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.3_getting-started_installation.md Provides commands to manually add the nuxt-auth-sanctum dependency to your project as a development dependency using different package managers like pnpm, yarn, or npm. ```bash # 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 ``` -------------------------------- ### Start Nuxt Development Server Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.1_contributing.md Starts the development server for the Nuxt playground application. This allows you to see your changes live during development. ```shell pnpm dev ``` -------------------------------- ### Nuxt Auth Sanctum Configuration Example Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.2_usage_configuration.md Provides a comprehensive example of the nuxt-auth-sanctum module configuration, detailing settings for base URL, user state, endpoints, CSRF handling, client retries, redirection logic, global middleware, and logging. ```javascript sanctum: { baseUrl: 'http://localhost:80', userStateKey: 'sanctum.user.identity', redirectIfAuthenticated: false, endpoints: { csrf: '/sanctum/csrf-cookie', login: '/login', logout: '/logout', user: '/api/user' }, csrf: { cookie: 'XSRF-TOKEN', header: 'X-XSRF-TOKEN' }, client: { retry: false }, redirect: { keepRequestedRoute: false, onLogin: '/', onLogout: '/', onAuthOnly: '/login', onGuestOnly: '/' }, globalMiddleware: { enabled: false, allow404WithoutAuth: true }, logLevel: 3 } ``` -------------------------------- ### Install Nuxt Auth Sanctum Package Manually Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.5_getting-started_installation.md Adds the `nuxt-auth-sanctum` dependency to your Nuxt.js project using package managers like pnpm, yarn, or npm. This is an alternative to using the Nuxt CLI for installation. ```bash # 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 ``` -------------------------------- ### Install Nuxt Auth Sanctum Package Manually Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_getting-started_installation.md Adds the nuxt-auth-sanctum dependency to your project as a development dependency using your preferred package manager (pnpm, yarn, or npm). ```bash # 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 ``` -------------------------------- ### Nuxt Auth Sanctum Module Configuration Example Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_usage_configuration.md Provides a complete example of the Nuxt Auth Sanctum module configuration object. It details settings for authentication modes, endpoints, CSRF handling, client options, redirects, and middleware. ```javascript sanctum: { mode: 'cookie', userStateKey: 'sanctum.user.identity', redirectIfAuthenticated: false, redirectIfUnauthenticated: false, endpoints: { csrf: '/sanctum/csrf-cookie', login: '/login', logout: '/logout', user: '/api/user', }, csrf: { cookie: 'XSRF-TOKEN', header: 'X-XSRF-TOKEN', }, client: { retry: false, initialRequest: true, }, redirect: { keepRequestedRoute: false, onLogin: '/', onLogout: '/', onAuthOnly: '/login', onGuestOnly: '/', }, globalMiddleware: { enabled: false, allow404WithoutAuth: true, }, logLevel: 3, appendPlugin: false, } ``` -------------------------------- ### Install Project Dependencies with PNPM Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.1_contributing.md Installs all necessary project dependencies using the PNPM package manager. This command is required before running development or build tasks. ```shell pnpm install ``` -------------------------------- ### Install nuxt-auth-sanctum Package Manually Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.6_getting-started_installation.md Details how to manually add the nuxt-auth-sanctum package as a development dependency to your Nuxt.js project using pnpm, yarn, or npm. ```bash # Using pnpm pnpm add -D nuxt-auth-sanctum ``` ```bash # Using yarn yarn add --dev nuxt-auth-sanctum ``` ```bash # Using npm npm install --save-dev nuxt-auth-sanctum ``` -------------------------------- ### Configure Nuxt Auth Sanctum Base URL Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.5_getting-started_installation.md Configures the `nuxt-auth-sanctum` module by setting the `baseUrl` for the Laravel API. This is a required step for the module to function correctly and communicate with your backend. ```typescript export default defineNuxtConfig({ // ... // nuxt-auth-sanctum options (also configurable via environment variables) sanctum: { baseUrl: 'http://localhost:80', // Laravel API }, }); ``` -------------------------------- ### Install Nuxt Auth Sanctum Manually Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.4_getting-started_installation.md Manually adds the nuxt-auth-sanctum dependency to your Nuxt.js project using package managers like pnpm, yarn, or npm. This method provides more control over the installation process. ```bash # 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 ``` -------------------------------- ### Register Nuxt Auth Sanctum Module Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.6_getting-started_installation.md Shows how to register the nuxt-auth-sanctum module in the `modules` array within your nuxt.config.ts file after manual installation. ```typescript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], }); ``` -------------------------------- ### Configure Nuxt Auth Sanctum Base URL Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.2_getting-started_installation.md Sets the required `baseUrl` option for the `nuxt-auth-sanctum` module in `nuxt.config.ts`. This specifies the URL of your Laravel API backend. ```typescript export default defineNuxtConfig({ // ... // nuxt-auth-sanctum options (also configurable via environment variables) sanctum: { baseUrl: 'http://localhost:80', // Laravel API }, }); ``` -------------------------------- ### Install Nuxt Module with nuxi Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.1_changelog.md Demonstrates the recommended command for adding the nuxt-auth-sanctum module to a Nuxt project using the `nuxi module add` command. ```bash nuxi module add nuxt-auth-sanctum ``` -------------------------------- ### Configure Nuxt Auth Sanctum Base URL Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.6_getting-started_installation.md Provides the required configuration for the nuxt-auth-sanctum module in nuxt.config.ts. It specifies the baseUrl for the Laravel API, which is essential for the module to connect to your backend. ```typescript export default defineNuxtConfig({ // ... // nuxt-auth-sanctum options (also configurable via environment variables) sanctum: { baseUrl: 'http://localhost:80', // Laravel API }, }); ``` -------------------------------- ### Basic Nuxt Auth Sanctum Configuration Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.6_usage_configuration.md Sets up the Nuxt Auth Sanctum module with the required `baseUrl` for the Laravel API. This is the minimum configuration needed to start using the module. ```typescript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], sanctum: { baseUrl: 'http://localhost:80', // Laravel API }, }); ``` -------------------------------- ### Basic Nuxt Auth Sanctum Configuration Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_usage_configuration.md Sets up the Nuxt Auth Sanctum module with the mandatory baseUrl pointing to the Laravel API. This is the minimum configuration required to start using the module. ```typescript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], sanctum: { baseUrl: 'http://localhost:80', // Laravel API }, }); ``` -------------------------------- ### Register Nuxt Auth Sanctum Module in nuxt.config.ts Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_getting-started_installation.md Registers the nuxt-auth-sanctum module by adding its name to the 'modules' array in your nuxt.config.ts file. This step is necessary if you installed the package manually. ```typescript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], }); ``` -------------------------------- ### Register Nuxt Auth Sanctum Module Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.5_getting-started_installation.md Manually registers the `nuxt-auth-sanctum` module in your Nuxt application's configuration file (`nuxt.config.ts`). This step is necessary if you installed the package manually. ```typescript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], }); ``` -------------------------------- ### Configure Nuxt Auth Sanctum Base URL Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.3_getting-started_installation.md Sets the required 'sanctum.baseUrl' configuration in nuxt.config.ts to specify the Laravel API endpoint. This is crucial for the module to establish communication with your backend. ```typescript export default defineNuxtConfig({ // ... // nuxt-auth-sanctum options (also configurable via environment variables) sanctum: { baseUrl: 'http://localhost:80', // Laravel API }, }); ``` -------------------------------- ### Add nuxt-auth-sanctum Module Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.1.md Installs the nuxt-auth-sanctum module into your Nuxt project using the Nuxt CLI. This command fetches and adds the necessary package and configurations. ```bash npx nuxi@latest module add nuxt-auth-sanctum ``` -------------------------------- ### useSanctumFetch Basic Usage Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_composables_usesanctumfetch.md Demonstrates the basic usage of `useSanctumFetch` to make a GET request to an API endpoint. ```javascript const { data, status, error, refresh } = await useSanctumFetch('/api/users'); ``` -------------------------------- ### LocalStorage Token Storage Example Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.4_usage_token-storage.md An example implementation of the `TokenStorage` interface using browser's `localStorage`. It handles saving and retrieving tokens, ensuring it works correctly in both client-side and server-side rendering contexts. ```TypeScript // LocalStorage example for Laravel Authentication token const tokenStorageKey = 'sanctum.storage.token'; const localTokenStorage: TokenStorage = { get: async () => { if (import.meta.server) { return undefined; } return window.localStorage.getItem(tokenStorageKey) ?? undefined; }, set: async (app: NuxtApp, token?: string) => { if (import.meta.server) { return; } if (!token) { window.localStorage.removeItem(tokenStorageKey); return; } window.localStorage.setItem(tokenStorageKey, token); }, }; export default defineAppConfig({ sanctum: { tokenStorage: localTokenStorage, }, }); ``` -------------------------------- ### Configure Nuxt Auth Sanctum Base URL Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_getting-started_installation.md Sets the required baseUrl for the Laravel API within the nuxt.config.ts file. This configuration is essential for the module to connect to your backend. ```typescript export default defineNuxtConfig({ // ... // nuxt-auth-sanctum options (also configurable via environment variables) sanctum: { baseUrl: 'http://localhost:80', // Laravel API }, }); ``` -------------------------------- ### Configure Nuxt Auth Sanctum Base URL Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.4_getting-started_installation.md Sets the base URL for the Laravel API within the nuxt.config.ts file. This configuration is crucial for the module to establish communication with your backend. ```typescript export default defineNuxtConfig({ // ... // nuxt-auth-sanctum options (also configurable via environment variables) sanctum: { baseUrl: 'http://localhost:80', // Laravel API }, }); ``` -------------------------------- ### Initialize and Use useSanctumClient Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.2_usage_composables_usesanctumclient.md Initializes the `useSanctumClient` composable to obtain an `ofetch` client instance. This client is pre-configured with CSRF token headers and cookie management for authenticated requests to the configured `baseUrl`. The example shows fetching user data from `/api/users`. ```javascript const client = useSanctumClient(); const { data, pending, error, refresh } = await useAsyncData('users', () => client('/api/users') ); ``` -------------------------------- ### Nuxt Configuration for Sanctum Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.1_.github_issue_template_bug_report.md Example configuration for the Nuxt-Auth-Sanctum module within nuxt.config.ts. It shows how to specify the base URL for the Laravel backend. ```typescript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], sanctum: { baseUrl: 'http://localhost:80', }, }); ``` -------------------------------- ### Configure Nuxt Auth Sanctum with baseUrl Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.5_usage_configuration.md Demonstrates the basic setup for the nuxt-auth-sanctum module in nuxt.config.ts, specifying the essential baseUrl for the Laravel API. ```typescript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], sanctum: { baseUrl: 'http://localhost:80', // Laravel API }, }); ``` -------------------------------- ### Nuxt Sanctum Guest Middleware Example Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.5_middleware_sanctum-guest.md Demonstrates applying the `sanctum:guest` middleware to a Nuxt.js page. This middleware redirects users if they are already authenticated, ensuring the page is only accessible to guests. It uses `definePageMeta` to configure the middleware. ```vue ``` -------------------------------- ### Register Nuxt Auth Sanctum Module Manually Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.2_getting-started_installation.md Manually registers the `nuxt-auth-sanctum` module in the `modules` array within your `nuxt.config.ts` file. ```typescript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], }); ``` -------------------------------- ### LocalStorage Token Storage Example Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.5_advanced_token-storage.md An example implementation of a custom token storage using browser's localStorage. It handles token retrieval and saving, with checks for server-side rendering to prevent errors. ```TypeScript const tokenStorageKey = 'sanctum.storage.token'; const localTokenStorage: TokenStorage = { get: async () => { if (import.meta.server) { return undefined; } return window.localStorage.getItem(tokenStorageKey) ?? undefined; }, set: async (app: NuxtApp, token?: string) => { if (import.meta.server) { return; } if (!token) { window.localStorage.removeItem(tokenStorageKey); return; } window.localStorage.setItem(tokenStorageKey, token); }, }; export default defineAppConfig({ sanctum: { tokenStorage: localTokenStorage, }, }); ``` -------------------------------- ### Nuxt Auth Sanctum Configuration Example Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.5_usage_configuration.md This snippet demonstrates a comprehensive configuration for the Nuxt Auth Sanctum module. It covers settings for authentication mode, user state management, redirect behaviors, API endpoints, CSRF handling, client options, and global middleware. This configuration is typically placed in the `nuxt.config.js` file. ```javascript sanctum: { mode: 'cookie', userStateKey: 'sanctum.user.identity', redirectIfAuthenticated: false, redirectIfUnauthenticated: false, endpoints: { csrf: '/sanctum/csrf-cookie', login: '/login', logout: '/logout', user: '/api/user', }, csrf: { cookie: 'XSRF-TOKEN', header: 'X-XSRF-TOKEN', }, client: { retry: false, initialRequest: true, }, redirect: { keepRequestedRoute: false, onLogin: '/', onLogout: '/', onAuthOnly: '/login', onGuestOnly: '/', }, globalMiddleware: { enabled: false, allow404WithoutAuth: true, }, logLevel: 3, appendPlugin: false, } ``` -------------------------------- ### Basic useLazySanctumFetch Request Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.5_composables_uselazysanctumfetch.md Demonstrates how to make a basic GET request to an API endpoint using `useLazySanctumFetch`. It fetches data asynchronously and provides access to `data`, `status`, `error`, and `refresh`. ```javascript const { data, status, error, refresh } = await useLazySanctumFetch('/api/users'); ``` -------------------------------- ### Use useSanctumClient to Fetch Data Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.6_composables_usesanctumclient.md Initializes the `useSanctumClient` composable to obtain an `ofetch` compatible client. This client is pre-configured with CSRF token handling and cookie management for secure API requests. The example shows fetching user data from `/api/users`. ```javascript const client = useSanctumClient(); const { data, status, error, refresh } = await useAsyncData('users', () => client('/api/users') ); ``` -------------------------------- ### Nuxt Auth Sanctum Module Configuration Example Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.4_usage_configuration.md This snippet demonstrates a complete configuration object for the Nuxt Auth Sanctum module. It outlines various settings such as authentication mode, user state key, redirect behaviors, API endpoints for authentication, CSRF token handling, client-side request options, and global middleware settings. ```javascript sanctum: { mode: 'cookie', userStateKey: 'sanctum.user.identity', redirectIfAuthenticated: false, redirectIfUnauthenticated: false, endpoints: { csrf: '/sanctum/csrf-cookie', login: '/login', logout: '/logout', user: '/api/user', }, csrf: { cookie: 'XSRF-TOKEN', header: 'X-XSRF-TOKEN', }, client: { retry: false, initialRequest: true, }, redirect: { keepRequestedRoute: false, onLogin: '/', onLogout: '/', onAuthOnly: '/login', onGuestOnly: '/', }, globalMiddleware: { enabled: false, allow404WithoutAuth: true, }, logLevel: 3, appendPlugin: false, } ``` -------------------------------- ### LocalStorage Token Storage Example (TypeScript) Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.6_advanced_token-storage.md An example implementation of a custom token storage using browser's `localStorage`. It handles token retrieval and saving, ensuring it's only used on the client-side and correctly removes tokens when logging out. ```typescript // LocalStorage example for Laravel Authentication token const tokenStorageKey = 'sanctum.storage.token'; const localTokenStorage: TokenStorage = { get: async () => { if (import.meta.server) { return undefined; } return window.localStorage.getItem(tokenStorageKey) ?? undefined; }, set: async (app: NuxtApp, token?: string) => { if (import.meta.server) { return; } if (!token) { window.localStorage.removeItem(tokenStorageKey); return; } window.localStorage.setItem(tokenStorageKey, token); }, }; export default defineAppConfig({ sanctum: { tokenStorage: localTokenStorage, }, }); ``` -------------------------------- ### Register Nuxt Auth Sanctum Module Manually Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.3_getting-started_installation.md Manually registers the nuxt-auth-sanctum module in the 'modules' section of your nuxt.config.ts file. This is an alternative to automatic registration. ```typescript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], }); ``` -------------------------------- ### Register Nuxt Auth Sanctum Module Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.4_getting-started_installation.md Registers the nuxt-auth-sanctum module in the 'modules' section of your nuxt.config.ts file. This step is necessary for the module's functionality to be active in your Nuxt application. ```typescript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], }); ``` -------------------------------- ### Manual Sanctum Initialization with Dependencies (TypeScript) Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_advanced_plugin-dependencies.md This example shows how to manually initialize the Sanctum authentication in a custom Nuxt plugin. It specifies dependencies like '@nuxtjs/i18n' and 'nuxt-auth-sanctum', and includes the 'sanctum:request' hook for header enrichment before calling the init function. ```typescript export default defineNuxtPlugin({ name: 'custom-auth', dependsOn: ['@nuxtjs/i18n', 'nuxt-auth-sanctum'], async setup(nuxtApp) { nuxtApp.hook('sanctum:request', (app, ctx, logger) => { ctx .options .headers .set("X-Language", app.$i18n.localeProperties.value.code) }) const { init } = useSanctumAuth() await init() } }) ``` -------------------------------- ### Troubleshoot User Authentication (401) Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.6_advanced_troubleshooting.md Guides users on diagnosing 401 authentication errors during plugin initialization. It highlights the importance of checking Nuxt logs for 'set-cookie header is missing' warnings and suggests verifying the SANCTUM_STATEFUL_DOMAINS configuration on the Laravel backend. ```javascript [nuxt-auth-sanctum:ssr] WARN [response] set-cookie header is missing [nuxt-auth-sanctum:ssr] ⚙ User is not authenticated on plugin initialization, status: 401 ``` -------------------------------- ### Basic useSanctumFetch Request Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.5_composables_usesanctumfetch.md Demonstrates how to make a basic GET request using the `useSanctumFetch` composable to an API endpoint. It shows how to access the response data, status, and error objects returned by the composable. ```vue const { data, status, error, refresh } = await useSanctumFetch('/api/users'); ``` -------------------------------- ### Use Sanctum Fetch for API Request Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.6_composables_usesanctumfetch.md Demonstrates the basic usage of the useSanctumFetch composable to make a GET request to '/api/users'. It shows how to destructure the returned data, status, error, and refresh properties. ```javascript const { data, status, error, refresh } = await useSanctumFetch('/api/users'); ``` -------------------------------- ### Manual Sanctum Initialization with Dependencies Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.4_usage_plugin-dependencies.md This example shows how to manually initialize the Sanctum authentication client within a custom Nuxt plugin. By disabling the automatic initial request (sanctum.client.initialRequest: false) and explicitly calling init() after specifying dependencies like @nuxtjs/i18n and nuxt-auth-sanctum, developers gain granular control over the authentication flow, ensuring all dependencies are loaded. ```typescript export default defineNuxtPlugin({ name: 'custom-auth', dependsOn: ['@nuxtjs/i18n', 'nuxt-auth-sanctum'], async setup() { const { init } = useSanctumAuth() await init() } }) ``` -------------------------------- ### Troubleshoot CSRF Mismatch (419) Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.6_advanced_troubleshooting.md Explains how to resolve CSRF token mismatch errors (419 status code) by correctly configuring SESSION_DOMAIN and SANCTUM_STATEFUL_DOMAINS in Laravel. It emphasizes that cookies are restricted to the same TLD and provides an example for multi-domain setups. ```dotenv # Example Laravel .env configuration SESSION_DOMAIN=.myapp.com SANCTUM_STATEFUL_DOMAINS=myapp.com,admin.myapp.com ``` -------------------------------- ### Nuxt Sanctum Guest Middleware Setup Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.3_usage_middleware_sanctum-guest.md Configures the `sanctum:guest` middleware for a Nuxt page to restrict access to unauthenticated users. If an authenticated user attempts to access this page, they will be redirected based on the `redirect.onGuestOnly` configuration or receive a 403 error. ```vue ``` -------------------------------- ### Basic Nuxt Auth Sanctum Configuration Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.4_usage_configuration.md Demonstrates the minimal configuration required for the Nuxt Auth Sanctum module, setting the `baseUrl` for the Laravel API. ```typescript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], sanctum: { baseUrl: 'http://localhost:80', // Laravel API }, }); ``` -------------------------------- ### Basic Nuxt Configuration Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.3_usage_configuration.md Sets up the nuxt-auth-sanctum module with the required baseUrl for the Laravel API. ```javascript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], sanctum: { baseUrl: 'http://localhost:80', // Laravel API }, }); ``` -------------------------------- ### Basic Nuxt Config with Sanctum Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.2_usage_configuration.md Sets up the nuxt-auth-sanctum module and defines the baseUrl for the Laravel API. This is the minimum required configuration. ```typescript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], sanctum: { baseUrl: 'http://localhost:80', // Laravel API }, }); ``` -------------------------------- ### Add Required Config to Fixture Environment Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.1_changelog.md A fix that ensures required configuration is correctly set up in the fixture environment, crucial for testing and development setup. ```javascript // Fix: Added required config to fixture env // This likely involves updating test setup files or environment variables // to include necessary configuration parameters for the module's fixtures. ``` -------------------------------- ### Use Sanctum App Config Composable Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.4_usage_composables_usesanctumappconfig.md This example shows how to use the `useSanctumAppConfig` composable in Nuxt.js to access application configuration settings, such as interceptor configurations. ```javascript const config = useSanctumAppConfig(); console.log(config.interceptors.onRequest); // appConfig.sanctum.interceptors.onRequest ``` -------------------------------- ### Nuxt Auth Sanctum Configuration Options Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.5_usage_configuration.md Provides a comprehensive list and description of all available configuration parameters for the nuxt-auth-sanctum module, detailing their purpose and default values. ```APIDOC Nuxt Auth Sanctum Configuration Options: baseUrl: The base URL of the Laravel API. Default: undefined mode: Authentication mode to work with Laravel API. Supported values: 'cookie', 'token'. Default: 'cookie' origin: The URL of the current application to use in Referrer header. Default: `useRequestUrl().origin` userStateKey: The key to use to store the user identity in the `useState` variable. Default: 'sanctum.user.identity' redirectIfAuthenticated: Determine whether to redirect the user if it is already authenticated on a login attempt. Default: false redirectIfUnauthenticated: Determine whether to redirect when the user got unauthenticated on any API request. Default: false endpoints.csrf: The endpoint to request a new CSRF token. Default: '/sanctum/csrf-cookie' endpoints.login: The endpoint to send user credentials to authenticate. Default: '/login' endpoints.logout: The endpoint to destroy current user session. Default: '/logout' endpoints.user: The endpoint to fetch current user data. Default: '/api/user' csrf.cookie: Name of the CSRF cookie to extract from server response. Default: 'XSRF-TOKEN' csrf.header: Name of the CSRF header to pass from client to server. Default: 'X-XSRF-TOKEN' client.retry: The number of times to retry a request when it fails. Default: false client.initialRequest: Determines whether to request the user identity on plugin initialization. Default: true redirect.keepRequestedRoute: Determines whether to keep the requested route when redirecting after login. Default: false redirect.onLogin: Route to redirect to when user is authenticated. If set to false, do nothing. Default: '/' redirect.onLogout: Route to redirect to when user is not authenticated. If set to false, do nothing. Default: '/' redirect.onAuthOnly: Route to redirect to when user has to be authenticated. If set to false, do nothing. Default: '/login' redirect.onGuestOnly: Route to redirect to when user has to be a guest. If set to false, do nothing. Default: '/' globalMiddleware.enabled: Determines whether the global middleware is enabled. Default: false globalMiddleware.prepend: Determines whether to allow 404 pages without authentication. Default: false globalMiddleware.allow404WithoutAuth: Determines whether to allow 404 page without authentication. Default: true logLevel: The level to use for the logger. Default: 3 appendPlugin: Determines whether to append the plugin to the Nuxt application. Default: false ``` -------------------------------- ### nuxt-auth-sanctum Configuration Options Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.2_usage_configuration.md Comprehensive list of configuration parameters for the nuxt-auth-sanctum module, detailing their purpose, default values, and usage. ```APIDOC nuxt-auth-sanctum Configuration Options: baseUrl: The base URL of the Laravel API. - Type: string - Default: undefined - Description: Required for API calls to your Laravel backend. origin: The URL of the current application to use in the Referrer header. - Type: string - Default: `useRequestUrl().origin` userStateKey: The key to use for storing user identity in the `useState` variable. - Type: string - Default: `sanctum.user.identity` redirectIfAuthenticated: Determines whether to redirect when a user is authenticated. - Type: boolean - Default: false endpoints.csrf: The endpoint to request a new CSRF token. - Type: string - Default: `/sanctum/csrf-cookie` endpoints.login: The endpoint to send user credentials for authentication. - Type: string - Default: `/login` endpoints.logout: The endpoint to destroy the current user session. - Type: string - Default: `/logout` endpoints.user: The endpoint to fetch current user data. - Type: string - Default: `/api/user` csrf.cookie: Name of the CSRF cookie to extract from the server response. - Type: string - Default: `XSRF-TOKEN` csrf.header: Name of the CSRF header to pass from client to server. - Type: string - Default: `X-XSRF-TOKEN` client.retry: The number of times to retry a request when it fails. - Type: number | false - Default: false redirect.keepRequestedRoute: Determines whether to keep the requested route when redirecting after login. - Type: boolean - Default: false redirect.onLogin: Route to redirect to when a user is authenticated. If set to false, do nothing. - Type: string | false - Default: `/` redirect.onLogout: Route to redirect to when a user is not authenticated. If set to false, do nothing. - Type: string | false - Default: `/` redirect.onAuthOnly: Route to redirect to when a user must be authenticated. If set to false, do nothing. - Type: string | false - Default: `/login` redirect.onGuestOnly: Route to redirect to when a user must be a guest. If set to false, do nothing. - Type: string | false - Default: `/` globalMiddleware.enabled: Determines whether the global middleware is enabled. - Type: boolean - Default: false globalMiddleware.allow404WithoutAuth: Determines whether to allow the 404 page without authentication. - Type: boolean - Default: true logLevel: The level to use for the logger. - Type: number - Default: 3 - Description: More details available at https://manchenkoff.gitbook.io/nuxt-auth-sanctum/0.2/other/checking-logs. ``` -------------------------------- ### Use Sanctum App Config Composable Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.6_composables_usesanctumappconfig.md This example shows how to instantiate the `useSanctumAppConfig` composable and access a specific configuration property, `interceptors.onRequest`, which reflects the module's settings. ```javascript const config = useSanctumAppConfig(); console.log(config.interceptors.onRequest); // appConfig.sanctum.interceptors.onRequest ``` -------------------------------- ### Build Nuxt Playground App Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.1_contributing.md Builds the Nuxt playground application for deployment or testing. This command compiles the project into a production-ready format. ```shell pnpm dev:build ``` -------------------------------- ### TokenStorage Interface Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.4_usage_token-storage.md Defines the contract for token storage handlers, specifying methods to get and set authentication tokens. It requires a Nuxt application instance for context. ```TypeScript /** * Handlers to work with authentication token. */ export interface TokenStorage { /** * Function to load a token from the storage. */ get: (app: NuxtApp) => Promise; /** * Function to save a token to the storage. */ set: (app: NuxtApp, token?: string) => Promise; } ``` -------------------------------- ### Nuxt Auth Sanctum Configuration Options Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.3_usage_configuration.md Lists and describes all available configuration parameters for the nuxt-auth-sanctum module, including their default values and purpose. ```APIDOC nuxt-auth-sanctum Configuration Options: baseUrl: The base URL of the Laravel API. - Type: string - Default: undefined origin: The URL of the current application to use in Referrer header. - Type: string - Default: `useRequestUrl().origin` userStateKey: The key to use to store the user identity in the useState variable. - Type: string - Default: `sanctum.user.identity` redirectIfAuthenticated: Determine to redirect when user is authenticated. - Type: boolean - Default: false endpoints.csrf: The endpoint to request a new CSRF token. - Type: string - Default: `/sanctum/csrf-cookie` endpoints.login: The endpoint to send user credentials to authenticate. - Type: string - Default: `/login` endpoints.logout: The endpoint to destroy current user session. - Type: string - Default: `/logout` endpoints.user: The endpoint to fetch current user data. - Type: string - Default: `/api/user` csrf.cookie: Name of the CSRF cookie to extract from server response. - Type: string - Default: `XSRF-TOKEN` csrf.header: Name of the CSRF header to pass from client to server. - Type: string - Default: `X-XSRF-TOKEN` client.retry: The number of times to retry a request when it fails. - Type: number | false - Default: false redirect.keepRequestedRoute: Determines whether to keep the requested route when redirecting after login. - Type: boolean - Default: false redirect.onLogin: Route to redirect to when user is authenticated. If set to false, do nothing. - Type: string | false - Default: `/` redirect.onLogout: Route to redirect to when user is not authenticated. If set to false, do nothing. - Type: string | false - Default: `/` redirect.onAuthOnly: Route to redirect to when user has to be authenticated. If set to false, do nothing. - Type: string | false - Default: `/login` redirect.onGuestOnly: Route to redirect to when user has to be a guest. If set to false, do nothing. - Type: string | false - Default: `/` globalMiddleware.enabled: Determines whether the global middleware is enabled. - Type: boolean - Default: false globalMiddleware.allow404WithoutAuth: Determines whether to allow 404 page without authentication. - Type: boolean - Default: true logLevel: The level to use for the logger. - Type: number - Default: 3 ``` -------------------------------- ### Clone Nuxt Auth Sanctum Repository Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.1_contributing.md Clones the Nuxt Auth Sanctum project repository from GitHub using the provided Git SSH URL. This is the first step to setting up the development environment. ```shell git clone git@github.com:manchenkoff/nuxt-auth-sanctum.git ``` -------------------------------- ### Nuxt RuntimeConfig Configuration Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.3_usage_configuration.md Shows how to configure nuxt-auth-sanctum options via Nuxt's runtimeConfig.public. ```javascript export default defineNuxtConfig({ modules: ['nuxt-auth-sanctum'], runtimeConfig: { public: { sanctum: { baseUrl: 'http://localhost:80', }, }, }, }); ``` -------------------------------- ### TokenStorage Interface Definition Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_advanced_token-storage.md Defines the interface for custom token storage handlers. It includes methods for getting and setting the authentication token, accepting the Nuxt application instance as a parameter. ```APIDOC TokenStorage: get: (app: NuxtApp) => Promise Function to load a token from the storage. set: (app: NuxtApp, token?: string) => Promise Function to save a token to the storage. ``` -------------------------------- ### Using useSanctumClient for API Requests Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.3_usage_composables_usesanctumclient.md Demonstrates initializing the `useSanctumClient` and using it with `useAsyncData` to fetch data from an API endpoint. The client is pre-configured for Sanctum authentication, including CSRF tokens and cookie management, and functions similarly to `ofetch`. ```javascript const client = useSanctumClient(); const { data, pending, error, refresh } = await useAsyncData('users', () => client('/api/users') ); ``` -------------------------------- ### Laravel CORS Configuration Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.1_.github_issue_template_bug_report.md Example configuration for CORS settings in a Laravel application's config/cors.php file. This is crucial for allowing requests from the Nuxt frontend, especially when credentials are required. ```php ['*'], 'allowed_methods' => ['*'], 'allowed_origins' => [ env('FRONTEND_URL', 'http://localhost:3000'), ], 'allowed_origins_patterns' => [], 'allowed_headers' => ['*'], 'exposed_headers' => [], 'max_age' => 0, 'supports_credentials' => true, ]; ``` -------------------------------- ### useSanctumFetch with Options Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_composables_usesanctumfetch.md Shows how to use `useSanctumFetch` with custom options, including HTTP method, query parameters, and `AsyncDataOptions` for data fetching configuration. ```javascript const { data, status, error, refresh } = await useSanctumFetch( '/api/users', { method: 'GET', query: { is_active: true, }, }, { pick: ['id'], }, ); ``` -------------------------------- ### Using useSanctumClient for API Requests Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.5_composables_usesanctumclient.md Demonstrates how to initialize the `useSanctumClient` composable and use the returned client to make an asynchronous data fetch request to `/api/users`. The client is pre-configured for Sanctum authentication and leverages the `ofetch` interface. ```javascript const client = useSanctumClient(); const { data, status, error, refresh } = await useAsyncData('users', () => client('/api/users') ); ``` -------------------------------- ### LocalStorage Token Storage Implementation Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_advanced_token-storage.md An example implementation of a custom token storage handler using the browser's `localStorage`. This handler saves and retrieves the token, ensuring it's only accessed on the client-side. ```typescript const tokenStorageKey = 'sanctum.storage.token'; const localTokenStorage: TokenStorage = { get: async () => { if (import.meta.server) { return undefined; } return window.localStorage.getItem(tokenStorageKey) ?? undefined; }, set: async (app: NuxtApp, token?: string) => { if (import.meta.server) { return; } if (!token) { window.localStorage.removeItem(tokenStorageKey); return; } window.localStorage.setItem(tokenStorageKey, token); }, }; export default defineAppConfig({ sanctum: { tokenStorage: localTokenStorage, }, }); ``` -------------------------------- ### Add Separate Gitbook Module Docs Source: https://github.com/arieagung/nuxt-auth-sanctum-doc/blob/master/manchenkoff.gitbook.io_nuxt-auth-sanctum_0.1_changelog.md Documentation update that includes a separate Gitbook for module documentation, improving clarity and accessibility for developers using the module. ```markdown ## Documentation - Added separate gitbook as module docs ```