Nuxt - Laravel Echo
GitHubNuxt Module
  • Getting Started
    • Introduction
    • Installation
  • Usage
    • Configuration
    • Cookie Authentication
    • Token Authentication
  • Composables
    • useEcho
    • useEchoConfig
    • useEchoAppConfig
  • Other
    • Token Storage
    • Interceptors
    • Breeze Nuxt template
Powered by GitBook
On this page
  • How it works
  • Custom token storage
  1. Usage

Token Authentication

How to setup Sanctum Bearer token-based authentication for Laravel Echo.

PreviousCookie AuthenticationNextuseEcho

Last updated 4 months ago

Token-based authentication is not recommended for SPA applications. Still, it might be useful when you cannot host it on the same TLD or have a mobile or desktop application built with Nuxt (e.g. based on Capacitor).

To explicitly set this authentication mode, update echo.authentication.mode configuration property to token.

You can check the official Laravel documentation here - .

How it works

You should already have an authenticated user by submitting credentials to your login endpoint, for instance, using the module.

Ensure that you use token mode for nuxt-auth-sanctum module to save the Bearer token from the API response on authentication requests.

Custom token storage

Default token storage uses cookies to keep the Authentication token and automatically load it for Echo channel authorization requests. However, you are free to define custom storage in your app.config.ts by implementing an interface (especially, when cookies are not supported, for example - Capacitor, Ionic, LocalStorage, etc).

Check this section for more details - .

API Token Authentication
Nuxt Auth Sanctum
Token storage