tlaverdure/laravel-echo-server

Authenticate users before websocket connection establishes

HASSANDL opened this issue · 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": ""
  }
}

iooe commented

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

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

    if (user !== null) {

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

    }`