Usage
Cookie authentication
How to setup Sanctum cookie-based authentication for Laravel Echo.
Configuration
By default, the module provides configuration to integrate seamlessly with Laravel Sanctum authentication based on the XSRF token.
To explicitly set this authentication mode, update echo.authentication.mode
configuration property to cookie
.
Nuxt and Laravel applications must share the same top-level domain. For instance:
- Nuxt application -
domain.com
- Laravel application -
api.domain.com
How it works
You should already have an authenticated user by submitting credentials to your login endpoint, for instance, using the Nuxt Auth Sanctum module.
Once the module has an authentication state, it will request a CSRF cookie from the API, and pass it as an XSRF header to each Echo channel authorization request to confirm the current user identity.
Ensure that you use
cookie
mode for nuxt-auth-sanctum
module
to save the CSRF cookie from the API response on authentication requests.