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

# Cookie Authentication

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](https://laravel.com/docs/11.x/sanctum#authorizing-private-broadcast-channels).

{% hint style="warning" %}
Nuxt and Laravel applications must share the same top-level domain.

For instance:

* Nuxt application - **`domain.com`**
* Laravel application - **`api.domain.com`**
{% endhint %}

## How it works

You should already have an authenticated user by submitting credentials to your login endpoint, for instance, using the [Nuxt Auth Sanctum](https://manchenkoff.gitbook.io/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.

{% hint style="info" %}
Ensure that you use `cookie` mode for `nuxt-auth-sanctum` module to save the CSRF cookie from the API response on authentication requests.
{% endhint %}
