laravel-echo-server icon indicating copy to clipboard operation
laravel-echo-server copied to clipboard

Authenticate users before websocket connection establishes

Open HASSANDL opened this issue 4 years ago • 2 comments

How only allow authenticated users to establish a successful websocket connection? in client side use laravel-echo

{
  "authHost": "http://localhost",
  "authEndpoint": "/broadcasting/auth",
  "clients": [
    {
      "appId": "620bafdba22974a2",
      "key": "e860c5fc92f4a20e7175754eb030e737"
    }
  ],
  "database": "redis",
  "databaseConfig": {
    "redis": {
      "host": "localhost",
      "port": 6379
    },
    "sqlite": {
      "databasePath": "/database/laravel-echo-server.sqlite"
    }
  },
  "devMode": true,
  "host": null,
  "port": 7000,
  "protocol": "http",
  "socketio": {
    "pingTimeout": 5000,
    "pingInterval": 2000000
  },
  "secureOptions": 67108864,
  "sslCertPath": "",
  "sslKeyPath": "",
  "sslCertChainPath": "",
  "sslPassphrase": "",
  "subscribers": {
    "http": false,
    "redis": true
  },
  "apiOriginAllow": {
    "allowCors": false,
    "allowOrigin": "",
    "allowMethods": "",
    "allowHeaders": ""
  }
}

HASSANDL avatar Jan 13 '21 22:01 HASSANDL

<meta name="user" content="{{Auth::user()}}"> `

    const user = document.querySelector('meta[name="user"]').getAttribute('content')

    if (user !== null) {

        this.echoInstance = new Echo({
          ...
        });

    }`

iooe avatar Feb 20 '21 04:02 iooe

https://laravel.com/docs/8.x/broadcasting#concept-overview

N3XT0R avatar Apr 20 '21 20:04 N3XT0R