Cookie Authentication

How to setup Sanctum cookie-based authentication for Laravel Echo.

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.

You can check the official Laravel documentation here - Authorizing Private Channels.

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.

Last updated